Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seq_explorer-0.1.1.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seq_explorer-0.1.1-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file seq_explorer-0.1.1.tar.gz.

File metadata

  • Download URL: seq_explorer-0.1.1.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

Hashes for seq_explorer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7470e2d32a63da294a1f0d2ea8aad893bd487dbee1f4ee5fa8c9ad9761d44894
MD5 c25f87bd1dc058a294798b33fb2f6cd7
BLAKE2b-256 555f5f2751745e3252b7d32f41bad5764436442abccb11501fe668314dc14ece

See more details on using hashes here.

File details

Details for the file seq_explorer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: seq_explorer-0.1.1-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

Hashes for seq_explorer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c490aeaa9d8177703ff664d16f206eb82183baafe809f0452c931b17dbf528a7
MD5 f619757c00192ca5afec783c686a90b2
BLAKE2b-256 addf5297999f3ecb046a8d6d64f07a44bcc9d772bc24052411cd7f7b6e36ec26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page