seedl 0.1.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.
- seedl-0.1.0/LICENSE +21 -0
- seedl-0.1.0/PKG-INFO +469 -0
- seedl-0.1.0/README.md +438 -0
- seedl-0.1.0/pyproject.toml +70 -0
- seedl-0.1.0/pyproject.toml.orig +49 -0
- seedl-0.1.0/scripts/verify_release.py +187 -0
- seedl-0.1.0/src/seedl/__init__.py +47 -0
- seedl-0.1.0/src/seedl/_activations.py +33 -0
- seedl-0.1.0/src/seedl/_compare.py +127 -0
- seedl-0.1.0/src/seedl/_datasets.py +191 -0
- seedl-0.1.0/src/seedl/_educational.py +331 -0
- seedl-0.1.0/src/seedl/_embeddings.py +134 -0
- seedl-0.1.0/src/seedl/_explain.py +321 -0
- seedl-0.1.0/src/seedl/_export.py +143 -0
- seedl-0.1.0/src/seedl/_gradients.py +24 -0
- seedl-0.1.0/src/seedl/_inspect.py +1357 -0
- seedl-0.1.0/src/seedl/_models.py +272 -0
- seedl-0.1.0/src/seedl/_network_renderers.py +1301 -0
- seedl-0.1.0/src/seedl/_neurons.py +450 -0
- seedl-0.1.0/src/seedl/_predictions.py +301 -0
- seedl-0.1.0/src/seedl/_spatial.py +269 -0
- seedl-0.1.0/src/seedl/_tensors.py +123 -0
- seedl-0.1.0/src/seedl/_training.py +348 -0
- seedl-0.1.0/src/seedl/_transformers.py +114 -0
- seedl-0.1.0/src/seedl/_vision.py +123 -0
- seedl-0.1.0/src/seedl/api.py +620 -0
- seedl-0.1.0/src/seedl/exceptions.py +13 -0
- seedl-0.1.0/src/seedl/py.typed +0 -0
- seedl-0.1.0/src/seedl/renderers.py +1471 -0
- seedl-0.1.0/src/seedl/view.py +134 -0
- seedl-0.1.0/tests/test_activations_gradients.py +169 -0
- seedl-0.1.0/tests/test_api.py +565 -0
- seedl-0.1.0/tests/test_cv_transformers_embeddings.py +141 -0
- seedl-0.1.0/tests/test_educational.py +104 -0
- seedl-0.1.0/tests/test_explainability.py +265 -0
- seedl-0.1.0/tests/test_export_and_backends.py +88 -0
- seedl-0.1.0/tests/test_model_explorer.py +91 -0
- seedl-0.1.0/tests/test_neuron_graph.py +452 -0
- seedl-0.1.0/tests/test_predictions_datasets.py +129 -0
- seedl-0.1.0/tests/test_review.py +293 -0
- seedl-0.1.0/tests/test_spatial.py +122 -0
- seedl-0.1.0/tests/test_tensor_explorer.py +75 -0
- seedl-0.1.0/tests/test_training_observability.py +130 -0
- seedl-0.1.0/tests/test_verify_release.py +95 -0
- seedl-0.1.0/uv.lock +2128 -0
seedl-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aritra Saha
|
|
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.
|
seedl-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: seedl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple, deep-learning-aware visualization library
|
|
5
|
+
Author: Aritra Saha
|
|
6
|
+
Author-email: Aritra Saha <aritrasab@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: torch>=2.0 ; extra == 'all'
|
|
10
|
+
Requires-Dist: numpy>=1.23 ; extra == 'all'
|
|
11
|
+
Requires-Dist: plotly>=5.18 ; extra == 'all'
|
|
12
|
+
Requires-Dist: matplotlib>=3.7 ; extra == 'all'
|
|
13
|
+
Requires-Dist: pytest>=7.4 ; extra == 'dev'
|
|
14
|
+
Requires-Dist: ruff>=0.4 ; extra == 'dev'
|
|
15
|
+
Requires-Dist: mypy>=1.8 ; extra == 'dev'
|
|
16
|
+
Requires-Dist: tomli>=2 ; python_full_version < '3.11' and extra == 'dev'
|
|
17
|
+
Requires-Dist: matplotlib>=3.7 ; extra == 'matplotlib'
|
|
18
|
+
Requires-Dist: numpy>=1.23 ; extra == 'numpy'
|
|
19
|
+
Requires-Dist: plotly>=5.18 ; extra == 'plotly'
|
|
20
|
+
Requires-Dist: torch>=2.0 ; extra == 'torch'
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Project-URL: Repository, https://github.com/iamaritrasaha/seedl
|
|
23
|
+
Project-URL: Issues, https://github.com/iamaritrasaha/seedl/issues
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Provides-Extra: matplotlib
|
|
27
|
+
Provides-Extra: numpy
|
|
28
|
+
Provides-Extra: plotly
|
|
29
|
+
Provides-Extra: torch
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# SeeDL
|
|
33
|
+
|
|
34
|
+
SeeDL turns a PyTorch model into a visual network you can inspect.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import seedl as sd
|
|
38
|
+
|
|
39
|
+
sd.see(model)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For a supported small MLP, this draws actual neurons and connections from the model's weights.
|
|
43
|
+
Rotate the network in three dimensions with:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
sd.see(model, view="3d")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
These screenshots show an initialized 4 → 8 → 6 → 2 PyTorch model, not an artist's mockup.
|
|
53
|
+
See the [executed visual showcase](examples/neural_network_explorer.ipynb),
|
|
54
|
+
[visual acceptance record](docs/VISUAL_ACCEPTANCE.md), and
|
|
55
|
+
[reproduction script](scripts/build_visual_showcase.py).
|
|
56
|
+
|
|
57
|
+
The zero-dependency core still supports SVG. Plotly, PyTorch, NumPy and Matplotlib remain
|
|
58
|
+
optional extras. Existing tensor, training, prediction, gradient, activation, attention,
|
|
59
|
+
explainability and educational APIs remain available.
|
|
60
|
+
|
|
61
|
+
## Explore a network
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import torch
|
|
65
|
+
from torch import nn
|
|
66
|
+
import seedl as sd
|
|
67
|
+
|
|
68
|
+
model = nn.Sequential(
|
|
69
|
+
nn.Linear(4, 8),
|
|
70
|
+
nn.ReLU(),
|
|
71
|
+
nn.Linear(8, 6),
|
|
72
|
+
nn.ReLU(),
|
|
73
|
+
nn.Linear(6, 2),
|
|
74
|
+
)
|
|
75
|
+
x = torch.tensor([[0.3, 0.8, -0.2, 1.0]])
|
|
76
|
+
|
|
77
|
+
sd.see(model) # Neurons and actual weighted edges
|
|
78
|
+
sd.see(model, select_neuron=(1, 2)) # Highlight incoming (cyan) & outgoing (amber) connections
|
|
79
|
+
sd.see(model, view="3d") # Plotly: orbit, zoom, pan
|
|
80
|
+
sd.see(model, input=x, theme="dark") # Actual post-activation node values
|
|
81
|
+
sd.see(model, input=x).explore() # Animated forward pass (Play/Pause/Reset) and layer-step slider
|
|
82
|
+
sd.see(model, view="architecture") # Operation blocks or module hierarchy
|
|
83
|
+
sd.see(model, view="summary") # Existing detailed inspection tables
|
|
84
|
+
|
|
85
|
+
view = sd.see(model, view="3d", input=x, select_neuron=(1, 2))
|
|
86
|
+
view.save("network.html") # Self-contained Plotly JS; opens offline
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
In notebooks, return the view as the last expression in a cell. In a script, call
|
|
90
|
+
`sd.see(model).show()` to open Plotly; the initial `see()` call prints a summary in terminals.
|
|
91
|
+
|
|
92
|
+
### What the picture means
|
|
93
|
+
|
|
94
|
+
- **Neurons:** Exact built-in `nn.Linear` and nested `nn.Sequential` networks are supported.
|
|
95
|
+
Supported intervening operations are ReLU, Tanh, Sigmoid, GELU, SiLU, LeakyReLU, ELU and
|
|
96
|
+
Identity. Activations annotate the preceding transformation instead of adding neuron layers.
|
|
97
|
+
Custom subclasses, hooks, functional operations inside custom `forward` methods and other
|
|
98
|
+
structures fall back to architecture inspection.
|
|
99
|
+
- **Connections:** An edge from input `i` to output `j` reads `weight[j, i]`. Teal means positive,
|
|
100
|
+
coral means negative, gray means exactly zero. Four line-width bins encode absolute weight
|
|
101
|
+
magnitude relative to the displayed edges. Hover includes the exact weight, parameter name,
|
|
102
|
+
trainability and existing weight gradient. Biases appear on neuron hover.
|
|
103
|
+
- **Activations:** `input=x` explicitly requests one eval/no-grad forward pass with a cloned
|
|
104
|
+
input. `sample=0` selects a zero-based batch row. Supported activation inputs have shape
|
|
105
|
+
`[features]` or `[batch, features]`. Each node shows the actual output after its activation;
|
|
106
|
+
hover also includes the Linear pre-activation. No input means no activation values.
|
|
107
|
+
Training flags, hooks and ordinary buffers are restored. Custom forward side effects are
|
|
108
|
+
not sandboxed in general architecture inspection.
|
|
109
|
+
- **Sharing and gradients:** Reused Linear modules appear at each Sequential occurrence;
|
|
110
|
+
parameter totals remain deduplicated. Missing gradients differ from zero gradients.
|
|
111
|
+
`color_by="gradient"` colors nodes by their existing **bias gradients**, with missing values
|
|
112
|
+
gray; edge colors still represent weights. SeeDL never calls backward automatically.
|
|
113
|
+
- **Coordinates:** Layer positions are deterministic layout coordinates, not learned embeddings.
|
|
114
|
+
In 3D each layer occupies a grid in a plane, making depth visible and the network rotatable.
|
|
115
|
+
|
|
116
|
+
### Model types and bounds
|
|
117
|
+
|
|
118
|
+
| Model | Automatic representation |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| Small supported MLP | Neurons and weighted connections |
|
|
121
|
+
| Sequential CNN | Connected operation blocks, channels, kernels, captured spatial dimensions |
|
|
122
|
+
| Transformer or custom/residual model | Module hierarchy; connectors mean containment |
|
|
123
|
+
| Large MLP | Architecture blocks, with explicit collapse disclosure |
|
|
124
|
+
| Other unsupported model | Existing informative inspection fallback |
|
|
125
|
+
|
|
126
|
+
Registration order does **not** establish custom execution order. SeeDL does not invent residual
|
|
127
|
+
or attention wiring, nor represent convolutional feature maps as fully connected neurons.
|
|
128
|
+
Architecture views show up to 40 blocks; use `view="summary"` for table inspection and `view.data`
|
|
129
|
+
for all rows. Progressive clickable module expansion is not implemented.
|
|
130
|
+
|
|
131
|
+
Defaults are **100 total neurons**, **48 per layer**, **12 layers**, and **1,500 connections**.
|
|
132
|
+
Models exceeding a neuron or layer limit fall back before extracting weight values. Configure
|
|
133
|
+
`max_neurons` (1–1,000) and `max_connections` (1–20,000); the per-layer and layer-count limits
|
|
134
|
+
remain in force. Edges are sampled evenly across flattened matrices using a deterministic
|
|
135
|
+
stride, then `min_weight` filters by absolute magnitude. This is a preview, not a strongest-edge
|
|
136
|
+
ranking. The plot discloses displayed versus total connections. Connections are batched into
|
|
137
|
+
sign/magnitude/layer traces, rather than creating a Plotly trace per edge.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
sd.see(model, max_neurons=100, max_connections=500, min_weight=0.1, edge_opacity=0.45)
|
|
141
|
+
sd.see(model, color_by="layer", theme="light")
|
|
142
|
+
sd.see(model, input=x, sample=0, color_by="activation")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Interactive and static output
|
|
146
|
+
|
|
147
|
+
Install `pip install "seedl[torch,plotly]"` for interactive model exploration. Plotly 3D uses
|
|
148
|
+
actual `Scatter3d` traces and a WebGL browser. Hover, sign-legend toggles, orbit, zoom and pan
|
|
149
|
+
are supported. **Orbit**, **Pan**, and **Reset view** controls sit above the graph. Reset view
|
|
150
|
+
restores the designed camera and orbit mode. Dotted outlines identify layer planes, not weights.
|
|
151
|
+
Colored node outlines preserve layer identity while the fill shows activation values.
|
|
152
|
+
Edge-on camera angles can overlap labels.
|
|
153
|
+
|
|
154
|
+
`.explore()` provides animated forward propagation (**▶ Play**, **⏸ Pause**, **⏮ Reset**) with
|
|
155
|
+
speed controls (**0.5x**, **1x**, **2x**) and a layer-step slider. It visually steps through computational
|
|
156
|
+
transformations in execution order, highlighting active transformations and displaying actual captured
|
|
157
|
+
tensors without inventing intermediate values. Without a captured input, exploration explicitly indicates
|
|
158
|
+
that values are unavailable.
|
|
159
|
+
|
|
160
|
+
Users can also select and inspect individual neurons via `select_neuron=(layer, idx)` or through the
|
|
161
|
+
interactive dropdown menu. Selecting a neuron isolates its incoming connections (cyan) and outgoing
|
|
162
|
+
connections (amber), dims unrelated edges, and provides a full inspection panel with module identity,
|
|
163
|
+
operation, bias, trainability, activation, pre-activation, and gradient values. There is no external
|
|
164
|
+
server requirement, notebook widget dependency, or fake particle physics.
|
|
165
|
+
|
|
166
|
+
Without Plotly, `sd.see(model)` renders SVG circles, edges, labels and native title tooltips.
|
|
167
|
+
Explicit `view="3d"` requires Plotly and raises an installation hint if it is absent. Unsupported
|
|
168
|
+
3D model requests use an explicitly disclosed 2D architecture fallback. SVG/Matplotlib export
|
|
169
|
+
of a 3D neuron network is labeled as a **2D projection**. Python-side 3D raster export requires
|
|
170
|
+
Plotly's optional Kaleido setup. The browser toolbar can download a genuine 3D PNG without
|
|
171
|
+
Kaleido; this was tested and [the output inspected](docs/visuals/network-3d-export.png).
|
|
172
|
+
HTML is the portable interactive export.
|
|
173
|
+
|
|
174
|
+
Notebooks must trust the output and support Plotly MIME rendering. GitHub's notebook viewer
|
|
175
|
+
may not execute interactive output; use Jupyter or generated HTML. Small panels can require
|
|
176
|
+
scrolling. Browser inspection was completed in the Codex in-app browser; other frontends and
|
|
177
|
+
GPU/WebGL configurations have not all been tested.
|
|
178
|
+
|
|
179
|
+
### More spatial views
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
sd.embeddings(vectors, dimensions=3, labels=names, categories=groups)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Three-component PCA requires NumPy and Plotly, at least three vectors and three features.
|
|
186
|
+
It fits an evenly sampled preview (default 128 vectors; configurable up to 5,000), reports
|
|
187
|
+
per-component explained variance, and handles rank-deficient data explicitly. Labels and
|
|
188
|
+
categories refer to the original rows. Coordinates use a disclosed common input scale to avoid
|
|
189
|
+
numeric overflow; `view.data["coordinate_scale"]` records it. These coordinates can distort
|
|
190
|
+
high-dimensional distances. Existing `dimensions=2` behavior is preserved.
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
regressor = nn.Linear(1, 1)
|
|
194
|
+
features = torch.linspace(-1, 1, 20).reshape(-1, 1)
|
|
195
|
+
targets = 2 * features + 0.5
|
|
196
|
+
sd.loss_landscape(
|
|
197
|
+
regressor,
|
|
198
|
+
(features, targets),
|
|
199
|
+
loss_fn=nn.functional.mse_loss,
|
|
200
|
+
axes=(("weight", 0), ("bias", 0)),
|
|
201
|
+
radius=1.5,
|
|
202
|
+
steps=15,
|
|
203
|
+
evaluate=True,
|
|
204
|
+
)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
This is a **sampled two-dimensional coordinate slice of parameter space**, rendered with a
|
|
208
|
+
Plotly `Surface`. Axis indices address flattened parameter coordinates; all other parameters
|
|
209
|
+
stay fixed. `evaluate=True` is required because the call runs repeated forward evaluations on
|
|
210
|
+
a deep copy. CPU models up to 250,000 parameters and grids of 3–31 steps per axis are supported
|
|
211
|
+
(default 225 grid evaluations, maximum 961). A scalar `loss_fn` is required. Optional
|
|
212
|
+
`trajectory=[(axis1_offset, axis2_offset), ...]` evaluates up to 100 extra points in the same
|
|
213
|
+
slice; this does not capture an optimizer automatically. Original model parameters, gradients,
|
|
214
|
+
buffers, training flags and CPU RNG are preserved. External side effects of arbitrary custom
|
|
215
|
+
Python callbacks cannot be sandboxed. The cost also depends on the supplied input and model.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Key Capabilities
|
|
220
|
+
|
|
221
|
+
- **Multidimensional Tensor Explorer:** Scalars, 1D signals, 2D matrices, image tensors (CHW/HWC), batch grids, channel decomposition, memory footprints, and value distributions.
|
|
222
|
+
- **Model Architecture & Shape Tracing:** Clean module hierarchy, parameter counting (trainable vs frozen), shared parameter deduplication, and hook-based shape tracing.
|
|
223
|
+
- **Activations & Feature Maps:** Layer outputs, convolutional feature map grids, saturation diagnostics, and heuristic dead unit alerts (>80% inactive zeros in ReLU/GELU).
|
|
224
|
+
- **Gradient Flow Observability:** Observational, non-intrusive parameter gradient inspection, L2 norm metrics, and heuristic alerts for vanishing (<1e-7), exploding (>100), non-finite (NaN/Inf), or all-zero layers without modifying model parameters.
|
|
225
|
+
- **Training Observability & Tracking:** Exponential moving average (EMA) smoothing, multi-metric grouping, divergence/plateau/overfitting alerts, lightweight `Tracker` class, and run comparison (`sd.compare`).
|
|
226
|
+
- **Prediction Analysis:** Top-k classification ranking, logit vs normalized probability detection, regression residuals ($y_{pred} - y_{true}$), MAE/MSE/RMSE metrics, and multi-model comparison (`sd.compare_predictions`).
|
|
227
|
+
- **Dataset & DataLoader Inspection:** Bounded inspection of PyTorch `Dataset` and `DataLoader` batches, image tile grids, tabular column distributions, and class frequencies without exhausting streams or downloading full datasets.
|
|
228
|
+
- **CNNs & Transformers:** 2D discrete cross-correlation simulations (following deep learning Conv2d conventions for kernel, stride, padding, and receptive field) and multi-head attention heatmaps (self- and cross-attention) with query-key token labels and causal mask detection.
|
|
229
|
+
- **Vector Embeddings:** Pairwise cosine similarity matrix and analytical 2D PCA projections with explained variance ratio.
|
|
230
|
+
- **Explainability & Attribution:** Feature attribution using Vanilla Saliency, Integrated Gradients (with interpolation steps), and Grad-CAM for convolutional networks, with strict state and gradient preservation.
|
|
231
|
+
- **Educational Concept Simulations:** Interactive visual simulations of core deep learning concepts via `sd.learn(...)` (Gradient Descent, Backpropagation chain rule, Attention, Activation functions, Loss functions, Dropout, Batch Normalization, and Convolution).
|
|
232
|
+
- **Flexible Export & Multi-Backend:** Built-in SVG fallback (zero dependencies), interactive Plotly figures, static Matplotlib figures, `.save("path.html" | ".svg" | ".png")`, and interactive switching via `.explore()`.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Installation
|
|
237
|
+
|
|
238
|
+
Python 3.10 or newer is supported. The core package operates purely on the Python standard library:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
pip install seedl
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Install optional dependencies on demand:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
pip install "seedl[torch]" # PyTorch models, tensors, activations, explainability
|
|
248
|
+
pip install "seedl[numpy]" # NumPy arrays and fast SVD
|
|
249
|
+
pip install "seedl[plotly]" # Interactive web visualizations (recommended)
|
|
250
|
+
pip install "seedl[matplotlib]" # Static plotting and PNG exports
|
|
251
|
+
pip install "seedl[all]" # All capabilities and backends
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Optional dependencies are imported strictly on demand. Importing `seedl` does not eagerly load PyTorch, NumPy, Plotly, or Matplotlib.
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Quick Start
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
import seedl as sd
|
|
262
|
+
|
|
263
|
+
# 1. Visualize a scalar with custom unit / note
|
|
264
|
+
sd.see(0.0035)
|
|
265
|
+
|
|
266
|
+
# 2. Visualize a numeric sequence or loss signal
|
|
267
|
+
sd.see([1.2, 2.5, 3.1, 2.8, 4.0, 5.2, 4.9])
|
|
268
|
+
|
|
269
|
+
# 3. Visualize a 2D matrix or correlation table
|
|
270
|
+
matrix = [
|
|
271
|
+
[1.0, 0.5, 0.2],
|
|
272
|
+
[0.5, 2.0, 0.8],
|
|
273
|
+
[0.2, 0.8, 1.5],
|
|
274
|
+
]
|
|
275
|
+
view = sd.see(matrix)
|
|
276
|
+
|
|
277
|
+
# 4. Export visualization directly to HTML, SVG, or PNG
|
|
278
|
+
view.save("matrix_view.html")
|
|
279
|
+
view.save("matrix_view.svg")
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
In a Jupyter/Colab notebook, visualizations render as rich interactive cell outputs. In a terminal, SeeDL displays a concise, informative text summary.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Core Workflows
|
|
287
|
+
|
|
288
|
+
### 1. PyTorch Model Inspection & Shape Tracing
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
import torch
|
|
292
|
+
import torch.nn as nn
|
|
293
|
+
import seedl as sd
|
|
294
|
+
|
|
295
|
+
model = nn.Sequential(
|
|
296
|
+
nn.Conv2d(3, 16, 3, padding=1),
|
|
297
|
+
nn.ReLU(),
|
|
298
|
+
nn.AdaptiveAvgPool2d((4, 4)),
|
|
299
|
+
nn.Flatten(),
|
|
300
|
+
nn.Linear(16 * 4 * 4, 10),
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
# Hierarchy and parameter counts:
|
|
304
|
+
sd.see(model)
|
|
305
|
+
|
|
306
|
+
# Trace tensor shapes across layers with an example input:
|
|
307
|
+
example = torch.randn(2, 3, 32, 32)
|
|
308
|
+
sd.see(model, input=example)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 2. Activations and Convolution Feature Maps
|
|
312
|
+
|
|
313
|
+
Capture layer activations from an input-driven forward pass:
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
act_view = sd.activations(model, input=example)
|
|
317
|
+
# act_view includes intermediate stats, feature map grid previews, and dead-unit diagnostics
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### 3. Gradient Flow Diagnostics
|
|
321
|
+
|
|
322
|
+
Inspect gradients that already exist on a model after `loss.backward()`:
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
output = model(example).sum()
|
|
326
|
+
output.backward()
|
|
327
|
+
|
|
328
|
+
grad_view = sd.gradients(model)
|
|
329
|
+
# Warns automatically about vanishing gradients (<1e-7), exploding gradients (>100), or all-zero layers.
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### 4. Training Observability and Experiment Tracking
|
|
333
|
+
|
|
334
|
+
Track metrics during training with the lightweight `Tracker`:
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
tracker = sd.watch(name="baseline_run")
|
|
338
|
+
|
|
339
|
+
for epoch in range(1, 11):
|
|
340
|
+
# ... training step ...
|
|
341
|
+
tracker.log(epoch=epoch, loss=train_loss, val_loss=val_loss, accuracy=acc)
|
|
342
|
+
|
|
343
|
+
# Visualize training curves with exponential moving average (EMA) smoothing:
|
|
344
|
+
sd.see(tracker)
|
|
345
|
+
|
|
346
|
+
# Compare two runs side by side:
|
|
347
|
+
sd.compare(run_a_history, run_b_history, names=("SGD", "AdamW"))
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### 5. Prediction Inspection & Error Residuals
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
# Multiclass classification: Top-k ranking and probability normalization:
|
|
354
|
+
logits = [2.4, 0.2, -1.5, 0.9]
|
|
355
|
+
labels = ["cat", "dog", "bird", "fish"]
|
|
356
|
+
sd.predictions(logits, labels=labels, task="classification")
|
|
357
|
+
|
|
358
|
+
# Regression: Residual error analysis, MAE, MSE, RMSE:
|
|
359
|
+
sd.predictions(y_pred, targets=y_true, task="regression")
|
|
360
|
+
|
|
361
|
+
# Model prediction agreement / disagreement comparison:
|
|
362
|
+
sd.compare_predictions(preds_model_a, preds_model_b, labels=labels)
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### 6. Dataset & DataLoader Batch Inspection
|
|
366
|
+
|
|
367
|
+
Safely preview a dataset or DataLoader batch without exhausting generators:
|
|
368
|
+
|
|
369
|
+
```python
|
|
370
|
+
from torch.utils.data import DataLoader
|
|
371
|
+
|
|
372
|
+
loader = DataLoader(my_dataset, batch_size=16)
|
|
373
|
+
sd.dataset(loader) # Automatically shows tiled image grid or tabular feature summaries
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### 7. Feature Attribution & Explainability
|
|
377
|
+
|
|
378
|
+
Inspect which input features influenced a model's prediction:
|
|
379
|
+
|
|
380
|
+
```python
|
|
381
|
+
# Saliency maps (input gradient sensitivity):
|
|
382
|
+
sd.explain(model, input=sample, method="saliency")
|
|
383
|
+
|
|
384
|
+
# Integrated Gradients (path-integrated attribution satisfying completeness via composite midpoint rule):
|
|
385
|
+
sd.explain(model, input=sample, method="integrated_gradients", steps=25)
|
|
386
|
+
|
|
387
|
+
# Grad-CAM (coarse spatial activation mapping for convnets):
|
|
388
|
+
sd.explain(conv_model, input=sample_image, method="grad_cam")
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
*Guaranteed state safety:* `sd.explain` preserves original model training flags, temporary hooks, and pre-existing parameter gradients.
|
|
392
|
+
|
|
393
|
+
### 8. Convolution & Transformer Attention
|
|
394
|
+
|
|
395
|
+
```python
|
|
396
|
+
# Exact 2D discrete cross-correlation simulation with arithmetic:
|
|
397
|
+
sd.convolution(image=my_image, kernel=sobel_kernel, stride=1, padding=1)
|
|
398
|
+
|
|
399
|
+
# Multi-head attention heatmaps with query/key token alignment:
|
|
400
|
+
sd.attention(attention_matrix, tokens=["The", "model", "learns", "fast"])
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### 9. Vector Embeddings & PCA
|
|
404
|
+
|
|
405
|
+
```python
|
|
406
|
+
# Pairwise cosine similarity matrix and analytical 2D PCA projection:
|
|
407
|
+
sd.embeddings(embedding_vectors, labels=["doc_1", "doc_2", "query_1"])
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### 10. Educational Concept Simulations (`sd.learn`)
|
|
411
|
+
|
|
412
|
+
Explore fundamental deep learning mechanisms interactively:
|
|
413
|
+
|
|
414
|
+
```python
|
|
415
|
+
sd.learn("gradient_descent", lr=0.15, steps=12)
|
|
416
|
+
sd.learn("backpropagation")
|
|
417
|
+
sd.learn("attention")
|
|
418
|
+
sd.learn("activation_functions")
|
|
419
|
+
sd.learn("loss_functions")
|
|
420
|
+
sd.learn("dropout", p=0.5)
|
|
421
|
+
sd.learn("batch_norm")
|
|
422
|
+
sd.learn("convolution")
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## Visualization Views & Export
|
|
428
|
+
|
|
429
|
+
Every SeeDL operation returns a `Visualization` instance:
|
|
430
|
+
|
|
431
|
+
```python
|
|
432
|
+
view = sd.see(obj)
|
|
433
|
+
|
|
434
|
+
# Switch to interactive Plotly exploration mode:
|
|
435
|
+
fig = view.explore()
|
|
436
|
+
|
|
437
|
+
# Export to standalone files:
|
|
438
|
+
view.save("report.html") # Self-contained HTML with embedded graphics
|
|
439
|
+
view.save("figure.svg") # Clean vector SVG
|
|
440
|
+
view.save("figure.png") # Raster PNG via Matplotlib
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
---
|
|
444
|
+
|
|
445
|
+
## Development & Verification
|
|
446
|
+
|
|
447
|
+
Run the test suite and quality checks:
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
uv sync --extra dev --extra all
|
|
451
|
+
uv run --extra dev --extra all pytest
|
|
452
|
+
uv run --extra dev ruff check .
|
|
453
|
+
uv run --extra dev ruff format --check .
|
|
454
|
+
uv run --extra dev mypy
|
|
455
|
+
uv build --no-sources
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## Documentation & Releases
|
|
461
|
+
|
|
462
|
+
- [Release Notes (v0.1.0)](docs/RELEASE_NOTES_0.1.0.md): Complete release summary of verified capabilities and limitations.
|
|
463
|
+
- [Publishing Guide](docs/PUBLISHING.md): Instructions for building, verifying, and publishing to PyPI via OIDC Trusted Publishing.
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## License
|
|
468
|
+
|
|
469
|
+
Released under the [MIT License](LICENSE).
|