Visualize hidden state evolution in sequence models
Project description
Sequence Explorer
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.
Two Ways to Use
As a Package (pip install)
pip install seq-explorer
In Python/Notebooks:
from seq_explorer import SequenceTrace
trace = SequenceTrace.from_arrays(...)
Run dashboard:
streamlit run src/seq_explorer/app.py
As a Project (clone & run)
git clone https://github.com/chris-santiago/seq-explorer
cd seq-explorer
uv sync
uv run python src/seq_explorer/build_cache.py dataframe your_data.csv -o cache.parquet
uv run streamlit run src/seq_explorer/app.py
What it shows
- Model score timeline — running P(fraud) at every timestep, color-coded green → red
- Hidden state heatmap — per-neuron activations across the sequence (any number of layers)
- Hidden state norms — L2 norm over time for all layers, plus rate-of-change bars
- Top-k neuron drill-down — neurons most correlated with the fraud score, traced over time
- Layer similarity — cosine similarity between consecutive hidden state layers
- Raw features table — the actual transaction data, highlighted at the selected timestep
- Metadata overlays — visualize categorical/numeric metadata on timelines (e.g., risk tiers, channels)
- Timestep scrubber — linked across all panels for synchronized inspection
Quick Start
# Install dependencies
uv sync
# Build cache from CSV/Parquet (auto-detects schema)
uv run python src/seq_explorer/build_cache.py dataframe your_data.csv -o cache.parquet
# Launch dashboard
uv run streamlit run src/seq_explorer/app.py
The dashboard auto-detects hidden state columns - just use any prefix pattern like h0_*, h1_* or encoder_*, decoder_*.
Usage Options
Option 1: Construct + Plot Directly in Jupyter (Simplest!)
No need to save files or run Streamlit. Just use the plotting functions:
from seq_explorer import (
SequenceTrace,
fraud_score_timeline,
hidden_state_heatmap,
hidden_norm_plot,
top_neuron_traces,
layer_similarity_plot,
raw_feature_heatmap,
feature_fraud_correlation,
metadata_timeline_overlay,
)
trace = SequenceTrace.from_arrays(
sequence_id=0,
label=1,
raw_features=my_features, # (seq_len, n_features)
feature_names=['amount', ...],
hidden_states=[h0, h1], # list of (seq_len, hidden_dim)
running_fraud_scores=scores, # (seq_len,)
)
# All plotting functions return Plotly figures - show them inline!
fraud_score_timeline(trace.running_fraud_scores).show()
hidden_state_heatmap(trace.hidden_states[0]).show()
hidden_norm_plot(trace.hidden_norms).show()
top_neuron_traces(
trace.hidden_states[0],
trace.top_neuron_indices[0],
trace.top_neuron_correlations[0]
).show()
Option 2: Construct + Save + Dashboard
# Save to Parquet
df = SequenceTrace.to_dataframe({0: trace})
df.write_parquet('cache.parquet')
# Launch dashboard
streamlit run src/seq_explorer/app.py
Option 3: From DataFrame
python src/seq_explorer/build_cache.py dataframe data.csv -o cache.parquet
Option 4: From Model
python src/seq_explorer/build_cache.py model \
--checkpoint model.ckpt \
--data transactions.pt \
--auto-select \
-o cache.parquet
Model Support
Works with any PyTorch sequence model:
- GRU - any number of layers
- LSTM - any number of layers
- RNN - any number of layers
- Custom architectures with different attribute names (e.g.,
encoder,rnn_module)
Project structure
seq-explorer/
├── seq_explorer/ # Package + CLI
│ ├── __init__.py
│ ├── app.py # Streamlit dashboard
│ ├── plots.py # Plotly figure builders
│ ├── extractor.py # Model trace extraction
│ ├── trace.py # Data models
│ └── build_cache.py # Cache builder CLI
├── docs/ # Documentation
├── demo/ # Demo notebooks
└── README.md
Documentation
See the docs/ folder for full documentation:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seq_explorer-0.1.0.tar.gz.
File metadata
- Download URL: seq_explorer-0.1.0.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e6f3675360967c6ff6d208f19a8ae988a699feae2fc66655b110e6fe6994ab2
|
|
| MD5 |
b0e30cde743796e722ac54caa6f55400
|
|
| BLAKE2b-256 |
8c2de889b09f48242c1adf0f8b55343aacafcf2afc680d895ade63abaaf0ff83
|
File details
Details for the file seq_explorer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seq_explorer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b7408ab3760ac91c13a933619d530446e920e441b35a15122db205ec18b2e3f
|
|
| MD5 |
39ce2d7ba769374b5dd9fd67f5613bce
|
|
| BLAKE2b-256 |
fdeb1f1812c61ebcab42d2d2a4b3770af2ef4a57b64ae9dede87f11ba93642f1
|