Skip to content

Architecture overview

This app combines sequence modeling with local explainability in one Streamlit workflow.

High-level flow

  1. Load data:
  2. demo generator or uploaded CSV/Parquet

  3. Build windows:

  4. sorted by entity and timestep
  5. sliding windows produce (x, y)

  6. Activate model:

  7. either train built-in GRU
  8. or load pretrained checkpoint

  9. Inspect window:

  10. compute prediction and hidden activations
  11. visualize hidden matrix over timesteps

  12. Explain selected window:

  13. run TimeSHAP pruning
  14. run event-level attribution
  15. run feature-level attribution

Core components

  • GRUClassifier
  • sequence encoder (nn.GRU) plus classification head
  • SequencePack
  • session payload for scaled windows, labels, and metadata
  • load_sequence_model_from_checkpoint
  • flexible loader for Lightning and raw state dict checkpoints
  • run_local_timeshap
  • adapter from app tensors to TimeSHAP local API

State model

The app stores active artifacts in st.session_state["trained"]:

  • active source (train or checkpoint)
  • model object
  • optional training history
  • SequencePack
  • train/validation indices
  • loader notes

This keeps model and preprocessing context aligned for downstream plotting and explanation.