Example Notebooks
The notebooks below are rendered directly from the examples/ folder in the repository. Each one can be run interactively on Binder (no local installation required) or downloaded and run locally.
Before you run — Backend & Import Order
Every notebook (and any script using BaseAttentive) requires the backend to be
set before Keras or BaseAttentive are imported. Follow this order every time:
# 1. Set the backend environment variables FIRST
import os
os.environ["BASE_ATTENTIVE_BACKEND"] = "tensorflow" # or "torch" / "jax"
os.environ["KERAS_BACKEND"] = "tensorflow" # must match above
# 2. Import Keras SECOND
import keras
# 3. Import BaseAttentive THIRD
import base_attentive
from base_attentive import BaseAttentive
If you skip step 1 or import in a different order, BaseAttentive will raise a
BackendConfigurationError because it cannot detect the backend after Keras
has already initialised.
Binder users: open a notebook, execute the very first cell (it already contains the environment setup), and then run the remaining cells in order. Do not skip the first cell.
Local users: the os.environ calls work only when they run before
any Keras import in the same Python process. If you have already imported
Keras in a prior cell or session, restart the kernel and re-run from the top.
# |
Notebook |
Topics covered |
|---|---|---|
01 |
Model creation, configuration inspection, save/load |
|
02 |
Hybrid vs. Transformer objective comparison |
|
03 |
Attention levels, cross / hierarchical / memory-augmented |
|
04 |
Domain application patterns, multi-output forecasting |
|
05 |
Kernel-robust training, DTW alignment, regularisation |
|
06 |
CRPSLoss — quantile / gaussian / mixture modes, MC sampling |
|
07 |
V2 Spec & Registry — |
|
08 |
Financial ML — walk-forward validation, IC/ICIR/Sharpe/drawdown, regime analysis, gradient saliency |
|
09 |
Interpretability — VSN weights, cross/hierarchical attention heatmaps, integrated gradients, multi-head diversity |
|
10 |
Benchmarking — 7 architecture variants vs baselines, efficiency frontier, hyperparameter sensitivity, noise robustness, statistical significance |
|
11 |
Landslide Susceptibility Mapping with Physics-Informed BaseAttentive |
Landslide Susceptibility — physics-informed FS regularisation, depth-profile attention, ensemble uncertainty, scenario-conditioned hazard curves, method comparison (LR/RF/BA) |
12 |
ICU Sepsis Early Warning — SOFA-informed regularisation, multi-horizon risk curves (+6 h/+12 h/+24 h), temporal attention heatmaps, ensemble epistemic uncertainty, calibration curves, method comparison (LR/RF/BA); PhysioNet 2019 integration guide |
|
12b |
ICU Sepsis Early Warning — Real Data: PhysioNet Challenge 2019 |
ICU Sepsis — PhysioNet 2019 Real Data — full 5-component SOFA score (SpO₂/FiO₂ respiratory proxy, Platelets, Bilirubin, MAP, Creatinine; GCS absent — noted), demo-mode fallback, SOFA-consistency plots, multi-horizon BA vs LR/RF on ~40 k real patients |
13 |
Flood Early Warning System with Physics-Informed BaseAttentive |
Flood Early Warning System — FSI physics prior (Manning bankfull ratio), multi-horizon alerts (+1 h/+3 h/+6 h/+12 h/+24 h), NWP future covariates, horizon-conditioned attention saliency, ensemble epistemic uncertainty, decision-curve analysis, confidence-gated alarm API (REST/MQTT) |
13b |
Flood EWS — Real Data Integration Guide — drop-in loaders for CAMELS-US, USGS NWIS, ERA5-Land, GloFAS, GRDC, and UK NRFA; unified |
|
14 |
PADR-Net Flood Forecasting — validated |
|
15 |
Advanced PADR-Net Workflow: Transfer, Uncertainty, and Stress Testing |
Advanced PADR-Net Workflow — leave-one-region-out transfer, physics-loss ablation, threshold calibration, MC-dropout uncertainty, and rainfall-intensification stress testing |