tslens
Which time steps and which features did your time series model actually use?
tslens is a Captum-compatible interpretability toolkit for deep time series models, giving you a consistent PyTorch interface to over a dozen interpretation methods. Unlike methods borrowed from vision and NLP, the ones implemented natively here account for the temporal dependency between neighbouring time steps and score the time and feature dimensions jointly rather than separately.
Docs: khairulislam.github.io/tslens · Paper: arXiv:2412.04532 · Code: github.com/khairulislam/tslens
Why tslens?
| Capability | tslens | Captum | Time Interpret | TSInterpret |
|---|---|---|---|---|
| Time-series-native attribution | ✓ | — | ✓ | ✓ |
| Classification and regression/forecasting workflows | ✓ | Generic | Method-dependent | Classification-focused |
| Individual forecast-horizon explanations | ✓ | Manual | Manual | — |
| Modern deep forecaster integrations | ✓ | — | — | — |
| Tested LLM-backed time-series models | ✓ | — | — | — |
Among these libraries, tslens is the only one with documented, tested integrations spanning recent TSlib architectures and LLM-backed time-series models, while also supporting classification, regression, individual forecast horizons, and multivariate time–feature attribution. A dash means no first-class documented support; custom integration may still be possible. See the full comparison.
Install
pip install tslens
Use
Works with any PyTorch model that maps (batch, seq_len, n_features) to predictions.
No training framework to adopt, no dataset format to conform to.
import torch
from tslens import WinTSR
inputs = torch.randn(16, 96, 7) # (batch, seq_len, n_features)
attr = WinTSR(model).attribute(
inputs,
baselines=torch.zeros_like(inputs),
threshold=0.5, # skip the least relevant time steps
)
attr.shape # (16, n_output, 96, 7) -- (batch, n_output, seq_len, n_features)
Plot it as a heatmap over (seq_len, n_features) and you can read off what the model used.
Options that matter
| Argument | Effect |
|---|---|
threshold |
Quantile of time-relevance below which steps are skipped in stage two. Higher is faster and sparser; 0.0 keeps every step. |
sliding_window_shapes |
Window over (time, features). Defaults to (1, 1). Widen the first entry to attribute over multi-step windows. |
baselines |
Replacement values for occluded regions. Defaults to zeros; tslens.get_baseline(inputs, "normal") gives other options. |
unflatten |
True (default) returns (batch, n_output, seq_len, n_features). False returns the flat (batch * n_output, ...) layout used internally. |
legacy_normalize |
Constructor flag. Restores the exact normalization used to produce the published numbers — see below. |
Multi-input models
Pass a tuple, get a tuple back. This is how you explain a TSlib model (DLinear, iTransformer, TimesNet, ...) — its four forward arguments split into two attributed inputs and two context tensors, with no wrapper class:
attr_enc, attr_mark = WinTSR(model).attribute(
inputs=(x_enc, x_mark_enc),
baselines=(torch.zeros_like(x_enc), torch.zeros_like(x_mark_enc)),
additional_forward_args=(x_dec, x_mark_dec),
)
More recipes
The integration cookbook has copy-paste snippets for dict/tuple model outputs, classification models, baseline choice, explaining a single forecast horizon, speed tuning, and troubleshooting. Two runnable notebooks: quickstart and TSlib models.
Requirements
torch, numpy, captum, and time-interpret.
Citation
@article{islam2024wintsr,
title={WinTSR: A Windowed Temporal Saliency Rescaling Method for Interpreting Time Series Deep Learning Models},
author={Islam, Md Khairul and Fox, Judy},
journal={arXiv preprint arXiv:2412.04532},
year={2024}
}
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 tslens-0.1.1.tar.gz.
File metadata
- Download URL: tslens-0.1.1.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b32aefa621de001c2a0af360d877cacfdf46ad891c9f52f54058739721c58024
|
|
| MD5 |
146a2bc1b34700eafdd7d341475a32a5
|
|
| BLAKE2b-256 |
27bdcdb9a01a0fb17457cddc8aeeca0b0088865228793cd189efbcc26bc6647d
|
Provenance
The following attestation bundles were made for tslens-0.1.1.tar.gz:
Publisher:
publish.yml on khairulislam/tslens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tslens-0.1.1.tar.gz -
Subject digest:
b32aefa621de001c2a0af360d877cacfdf46ad891c9f52f54058739721c58024 - Sigstore transparency entry: 2500165815
- Sigstore integration time:
-
Permalink:
khairulislam/tslens@c56399ffc917c162873fd1fc277b0a6da9dc9eb4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/khairulislam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c56399ffc917c162873fd1fc277b0a6da9dc9eb4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tslens-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tslens-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48c9ca08df07a4d70964b3c8914415947e8d36d65663529aef2417a0a28592ed
|
|
| MD5 |
bf7ea32d0c8f7a2045fcbb8757db441c
|
|
| BLAKE2b-256 |
32d398c80d82900faaec0c000c817cdcd9870a48b577b7bf32e1ac5b87877518
|
Provenance
The following attestation bundles were made for tslens-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on khairulislam/tslens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tslens-0.1.1-py3-none-any.whl -
Subject digest:
48c9ca08df07a4d70964b3c8914415947e8d36d65663529aef2417a0a28592ed - Sigstore transparency entry: 2500165818
- Sigstore integration time:
-
Permalink:
khairulislam/tslens@c56399ffc917c162873fd1fc277b0a6da9dc9eb4 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/khairulislam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c56399ffc917c162873fd1fc277b0a6da9dc9eb4 -
Trigger Event:
push
-
Statement type: