seq-explorer 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: seq-explorer
3
+ Version: 0.1.0
4
+ Summary: Visualize hidden state evolution in sequence models
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE.md
8
+ Requires-Dist: numpy>=2.4.2
9
+ Requires-Dist: pandas>=2.3.3
10
+ Requires-Dist: plotly>=6.5.2
11
+ Requires-Dist: polars>=1.38.1
12
+ Requires-Dist: streamlit>=1.54.0
13
+ Requires-Dist: torch>=2.10.0
14
+ Provides-Extra: dev
15
+ Requires-Dist: isort>=7.0.0; extra == "dev"
16
+ Requires-Dist: mkdocs-material>=9.7.1; extra == "dev"
17
+ Requires-Dist: mkdocs-table-reader-plugin>=3.1.0; extra == "dev"
18
+ Requires-Dist: mkdocstrings-python>=2.0.2; extra == "dev"
19
+ Requires-Dist: pre-commit>=4.5.1; extra == "dev"
20
+ Requires-Dist: pymdown-extensions>=10.20.1; extra == "dev"
21
+ Requires-Dist: ruff>=0.15.1; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # Sequence Explorer
25
+
26
+ Interactive Streamlit dashboard for visualizing how a sequence model's hidden state evolves over transaction sequences. Works with **any PyTorch RNN** (GRU, LSTM, RNN) with **any number of layers**.
27
+
28
+ ## Two Ways to Use
29
+
30
+ ### As a Package (pip install)
31
+
32
+ ```bash
33
+ pip install seq-explorer
34
+ ```
35
+
36
+ **In Python/Notebooks:**
37
+ ```python
38
+ from seq_explorer import SequenceTrace
39
+
40
+ trace = SequenceTrace.from_arrays(...)
41
+ ```
42
+
43
+ **Run dashboard:**
44
+ ```bash
45
+ streamlit run src/seq_explorer/app.py
46
+ ```
47
+
48
+ ### As a Project (clone & run)
49
+
50
+ ```bash
51
+ git clone https://github.com/chris-santiago/seq-explorer
52
+ cd seq-explorer
53
+ uv sync
54
+ uv run python src/seq_explorer/build_cache.py dataframe your_data.csv -o cache.parquet
55
+ uv run streamlit run src/seq_explorer/app.py
56
+ ```
57
+
58
+ ## What it shows
59
+
60
+ - **Model score timeline** — running P(fraud) at every timestep, color-coded green → red
61
+ - **Hidden state heatmap** — per-neuron activations across the sequence (any number of layers)
62
+ - **Hidden state norms** — L2 norm over time for all layers, plus rate-of-change bars
63
+ - **Top-k neuron drill-down** — neurons most correlated with the fraud score, traced over time
64
+ - **Layer similarity** — cosine similarity between consecutive hidden state layers
65
+ - **Raw features table** — the actual transaction data, highlighted at the selected timestep
66
+ - **Metadata overlays** — visualize categorical/numeric metadata on timelines (e.g., risk tiers, channels)
67
+ - **Timestep scrubber** — linked across all panels for synchronized inspection
68
+
69
+ ## Quick Start
70
+
71
+ ```bash
72
+ # Install dependencies
73
+ uv sync
74
+
75
+ # Build cache from CSV/Parquet (auto-detects schema)
76
+ uv run python src/seq_explorer/build_cache.py dataframe your_data.csv -o cache.parquet
77
+
78
+ # Launch dashboard
79
+ uv run streamlit run src/seq_explorer/app.py
80
+ ```
81
+
82
+ The dashboard auto-detects hidden state columns - just use any prefix pattern like `h0_*, h1_*` or `encoder_*, decoder_*`.
83
+
84
+ ## Usage Options
85
+
86
+ ### Option 1: Construct + Plot Directly in Jupyter (Simplest!)
87
+
88
+ No need to save files or run Streamlit. Just use the plotting functions:
89
+
90
+ ```python
91
+ from seq_explorer import (
92
+ SequenceTrace,
93
+ fraud_score_timeline,
94
+ hidden_state_heatmap,
95
+ hidden_norm_plot,
96
+ top_neuron_traces,
97
+ layer_similarity_plot,
98
+ raw_feature_heatmap,
99
+ feature_fraud_correlation,
100
+ metadata_timeline_overlay,
101
+ )
102
+
103
+ trace = SequenceTrace.from_arrays(
104
+ sequence_id=0,
105
+ label=1,
106
+ raw_features=my_features, # (seq_len, n_features)
107
+ feature_names=['amount', ...],
108
+ hidden_states=[h0, h1], # list of (seq_len, hidden_dim)
109
+ running_fraud_scores=scores, # (seq_len,)
110
+ )
111
+
112
+ # All plotting functions return Plotly figures - show them inline!
113
+ fraud_score_timeline(trace.running_fraud_scores).show()
114
+ hidden_state_heatmap(trace.hidden_states[0]).show()
115
+ hidden_norm_plot(trace.hidden_norms).show()
116
+ top_neuron_traces(
117
+ trace.hidden_states[0],
118
+ trace.top_neuron_indices[0],
119
+ trace.top_neuron_correlations[0]
120
+ ).show()
121
+ ```
122
+
123
+ ### Option 2: Construct + Save + Dashboard
124
+
125
+ ```python
126
+ # Save to Parquet
127
+ df = SequenceTrace.to_dataframe({0: trace})
128
+ df.write_parquet('cache.parquet')
129
+
130
+ # Launch dashboard
131
+ streamlit run src/seq_explorer/app.py
132
+ ```
133
+
134
+ ### Option 3: From DataFrame
135
+
136
+ ```bash
137
+ python src/seq_explorer/build_cache.py dataframe data.csv -o cache.parquet
138
+ ```
139
+
140
+ ### Option 4: From Model
141
+
142
+ ```bash
143
+ python src/seq_explorer/build_cache.py model \
144
+ --checkpoint model.ckpt \
145
+ --data transactions.pt \
146
+ --auto-select \
147
+ -o cache.parquet
148
+ ```
149
+
150
+ ## Model Support
151
+
152
+ Works with any PyTorch sequence model:
153
+
154
+ - **GRU** - any number of layers
155
+ - **LSTM** - any number of layers
156
+ - **RNN** - any number of layers
157
+ - Custom architectures with different attribute names (e.g., `encoder`, `rnn_module`)
158
+
159
+ ## Project structure
160
+
161
+ ```
162
+ seq-explorer/
163
+ ├── seq_explorer/ # Package + CLI
164
+ │ ├── __init__.py
165
+ │ ├── app.py # Streamlit dashboard
166
+ │ ├── plots.py # Plotly figure builders
167
+ │ ├── extractor.py # Model trace extraction
168
+ │ ├── trace.py # Data models
169
+ │ └── build_cache.py # Cache builder CLI
170
+ ├── docs/ # Documentation
171
+ ├── demo/ # Demo notebooks
172
+ └── README.md
173
+ ```
174
+
175
+ ## Documentation
176
+
177
+ See the `docs/` folder for full documentation:
178
+
179
+ - [Quick Start](docs/quickstart.md)
180
+ - [Dashboard Guide](docs/dashboard.md)
181
+ - [Cache Format](docs/cache-format.md)
182
+ - [Architecture](docs/architecture.md)
@@ -0,0 +1,159 @@
1
+ # Sequence Explorer
2
+
3
+ Interactive Streamlit dashboard for visualizing how a sequence model's hidden state evolves over transaction sequences. Works with **any PyTorch RNN** (GRU, LSTM, RNN) with **any number of layers**.
4
+
5
+ ## Two Ways to Use
6
+
7
+ ### As a Package (pip install)
8
+
9
+ ```bash
10
+ pip install seq-explorer
11
+ ```
12
+
13
+ **In Python/Notebooks:**
14
+ ```python
15
+ from seq_explorer import SequenceTrace
16
+
17
+ trace = SequenceTrace.from_arrays(...)
18
+ ```
19
+
20
+ **Run dashboard:**
21
+ ```bash
22
+ streamlit run src/seq_explorer/app.py
23
+ ```
24
+
25
+ ### As a Project (clone & run)
26
+
27
+ ```bash
28
+ git clone https://github.com/chris-santiago/seq-explorer
29
+ cd seq-explorer
30
+ uv sync
31
+ uv run python src/seq_explorer/build_cache.py dataframe your_data.csv -o cache.parquet
32
+ uv run streamlit run src/seq_explorer/app.py
33
+ ```
34
+
35
+ ## What it shows
36
+
37
+ - **Model score timeline** — running P(fraud) at every timestep, color-coded green → red
38
+ - **Hidden state heatmap** — per-neuron activations across the sequence (any number of layers)
39
+ - **Hidden state norms** — L2 norm over time for all layers, plus rate-of-change bars
40
+ - **Top-k neuron drill-down** — neurons most correlated with the fraud score, traced over time
41
+ - **Layer similarity** — cosine similarity between consecutive hidden state layers
42
+ - **Raw features table** — the actual transaction data, highlighted at the selected timestep
43
+ - **Metadata overlays** — visualize categorical/numeric metadata on timelines (e.g., risk tiers, channels)
44
+ - **Timestep scrubber** — linked across all panels for synchronized inspection
45
+
46
+ ## Quick Start
47
+
48
+ ```bash
49
+ # Install dependencies
50
+ uv sync
51
+
52
+ # Build cache from CSV/Parquet (auto-detects schema)
53
+ uv run python src/seq_explorer/build_cache.py dataframe your_data.csv -o cache.parquet
54
+
55
+ # Launch dashboard
56
+ uv run streamlit run src/seq_explorer/app.py
57
+ ```
58
+
59
+ The dashboard auto-detects hidden state columns - just use any prefix pattern like `h0_*, h1_*` or `encoder_*, decoder_*`.
60
+
61
+ ## Usage Options
62
+
63
+ ### Option 1: Construct + Plot Directly in Jupyter (Simplest!)
64
+
65
+ No need to save files or run Streamlit. Just use the plotting functions:
66
+
67
+ ```python
68
+ from seq_explorer import (
69
+ SequenceTrace,
70
+ fraud_score_timeline,
71
+ hidden_state_heatmap,
72
+ hidden_norm_plot,
73
+ top_neuron_traces,
74
+ layer_similarity_plot,
75
+ raw_feature_heatmap,
76
+ feature_fraud_correlation,
77
+ metadata_timeline_overlay,
78
+ )
79
+
80
+ trace = SequenceTrace.from_arrays(
81
+ sequence_id=0,
82
+ label=1,
83
+ raw_features=my_features, # (seq_len, n_features)
84
+ feature_names=['amount', ...],
85
+ hidden_states=[h0, h1], # list of (seq_len, hidden_dim)
86
+ running_fraud_scores=scores, # (seq_len,)
87
+ )
88
+
89
+ # All plotting functions return Plotly figures - show them inline!
90
+ fraud_score_timeline(trace.running_fraud_scores).show()
91
+ hidden_state_heatmap(trace.hidden_states[0]).show()
92
+ hidden_norm_plot(trace.hidden_norms).show()
93
+ top_neuron_traces(
94
+ trace.hidden_states[0],
95
+ trace.top_neuron_indices[0],
96
+ trace.top_neuron_correlations[0]
97
+ ).show()
98
+ ```
99
+
100
+ ### Option 2: Construct + Save + Dashboard
101
+
102
+ ```python
103
+ # Save to Parquet
104
+ df = SequenceTrace.to_dataframe({0: trace})
105
+ df.write_parquet('cache.parquet')
106
+
107
+ # Launch dashboard
108
+ streamlit run src/seq_explorer/app.py
109
+ ```
110
+
111
+ ### Option 3: From DataFrame
112
+
113
+ ```bash
114
+ python src/seq_explorer/build_cache.py dataframe data.csv -o cache.parquet
115
+ ```
116
+
117
+ ### Option 4: From Model
118
+
119
+ ```bash
120
+ python src/seq_explorer/build_cache.py model \
121
+ --checkpoint model.ckpt \
122
+ --data transactions.pt \
123
+ --auto-select \
124
+ -o cache.parquet
125
+ ```
126
+
127
+ ## Model Support
128
+
129
+ Works with any PyTorch sequence model:
130
+
131
+ - **GRU** - any number of layers
132
+ - **LSTM** - any number of layers
133
+ - **RNN** - any number of layers
134
+ - Custom architectures with different attribute names (e.g., `encoder`, `rnn_module`)
135
+
136
+ ## Project structure
137
+
138
+ ```
139
+ seq-explorer/
140
+ ├── seq_explorer/ # Package + CLI
141
+ │ ├── __init__.py
142
+ │ ├── app.py # Streamlit dashboard
143
+ │ ├── plots.py # Plotly figure builders
144
+ │ ├── extractor.py # Model trace extraction
145
+ │ ├── trace.py # Data models
146
+ │ └── build_cache.py # Cache builder CLI
147
+ ├── docs/ # Documentation
148
+ ├── demo/ # Demo notebooks
149
+ └── README.md
150
+ ```
151
+
152
+ ## Documentation
153
+
154
+ See the `docs/` folder for full documentation:
155
+
156
+ - [Quick Start](docs/quickstart.md)
157
+ - [Dashboard Guide](docs/dashboard.md)
158
+ - [Cache Format](docs/cache-format.md)
159
+ - [Architecture](docs/architecture.md)
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "seq-explorer"
3
+ version = "0.1.0"
4
+ description = "Visualize hidden state evolution in sequence models"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ dependencies = [
8
+ "numpy>=2.4.2",
9
+ "pandas>=2.3.3",
10
+ "plotly>=6.5.2",
11
+ "polars>=1.38.1",
12
+ "streamlit>=1.54.0",
13
+ "torch>=2.10.0",
14
+ ]
15
+
16
+ [project.optional-dependencies]
17
+ dev = [
18
+ "isort>=7.0.0",
19
+ "mkdocs-material>=9.7.1",
20
+ "mkdocs-table-reader-plugin>=3.1.0",
21
+ "mkdocstrings-python>=2.0.2",
22
+ "pre-commit>=4.5.1",
23
+ "pymdown-extensions>=10.20.1",
24
+ "ruff>=0.15.1",
25
+ ]
26
+
27
+ [project.scripts]
28
+ seq-explorer-build = "seq_explorer.build_cache:main"
29
+
30
+ [build-system]
31
+ requires = ["setuptools>=61", "wheel"]
32
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,41 @@
1
+ """
2
+ Sequence Explorer - Visualize hidden state evolution in sequence models.
3
+
4
+ Usage:
5
+ from seq_explorer import SequenceTrace
6
+ from seq_explorer import fraud_score_timeline, hidden_state_heatmap, ...
7
+
8
+ trace = SequenceTrace.from_arrays(...)
9
+
10
+ To run the dashboard:
11
+ streamlit run seq_explorer/app.py
12
+ """
13
+
14
+ from seq_explorer.plots import (
15
+ feature_fraud_correlation,
16
+ feature_snapshot_bar,
17
+ fraud_score_timeline,
18
+ hidden_norm_plot,
19
+ hidden_state_heatmap,
20
+ layer_similarity_plot,
21
+ metadata_timeline_overlay,
22
+ norm_delta_plot,
23
+ raw_feature_heatmap,
24
+ top_neuron_traces,
25
+ )
26
+ from seq_explorer.trace import SequenceTrace
27
+
28
+ __version__ = "0.1.0"
29
+ __all__ = [
30
+ "SequenceTrace",
31
+ "fraud_score_timeline",
32
+ "hidden_state_heatmap",
33
+ "hidden_norm_plot",
34
+ "norm_delta_plot",
35
+ "top_neuron_traces",
36
+ "layer_similarity_plot",
37
+ "raw_feature_heatmap",
38
+ "feature_fraud_correlation",
39
+ "feature_snapshot_bar",
40
+ "metadata_timeline_overlay",
41
+ ]