Time Interpret: a Unified Model Interpretability Library for Time Series

Joseph EnguehardarXiv 2023 · DOI

Abstract

Deep learning models for time series data are often treated as black boxes, despite their use in critical domains like finance and medicine. Existing Explainable AI (XAI) tools frequently fail to account for temporal dependencies and the risk of future leakage. We introduce time_interpret (or tint), an open-source Python library extending Captum to provide a unified framework for time series interpretability. tint offers specialized attribution methods, robust evaluation metrics, and benchmark datasets, filling a critical gap in the XAI ecosystem.

1. Introduction

Deep learning models are increasingly deployed for high-stakes decision-making in fields such as medicine and finance. However, their "black box" nature remains a significant barrier to trust and adoption. While general XAI tools like SHAP or Integrated Gradients are widely used, they often fail to address the unique challenges of time series data, such as sequential dependencies and the strict temporal ordering of events. Standard tools may inadvertently introduce "future leakage"—using information from future time steps to explain a past prediction—or struggle with the high dimensionality of multivariate sequences. To address these issues, we present time_interpret (tint), a unified framework designed to bring robust interpretability to temporal data.

2. Methods

tint is built as an extension of the Captum library, providing a PyTorch-native interface for time-series-specific attribution. It introduces several novel and adapted algorithms:

2.1 Temporal Integrated Gradients (TIG)

Standard Integrated Gradients interpolate the entire input sequence against a baseline. In contrast, TIG respects temporal logic by cropping the sequence at time $t$ and only interpolating the most recent data point. This approach keeps the baseline closer to the actual sequence history, providing more localized and contextually relevant explanations.

Temporal interpolation logic used in TIG to avoid uninformative baselines and respect temporal ordering.

2.2 Time Forward Tunnel

This wrapper ensures that any attribution method operates iteratively. It forces the explanation for a prediction at time $t$ to only consider data available up to that moment, effectively preventing data leakage from the future.

2.3 Robust Attribution Techniques

  • Augmented Occlusion: Instead of using a static "zero" baseline, this method samples baselines from a bootstrapped distribution, ensuring perturbed data remains within the original dataset's distribution.
  • LOF-based Methods (LofLime, LofKernelShap): These utilize the Local Outlier Factor (LOF) to weight samples, prioritizing "inliers" to make explanations more robust against outliers.
  • NonLinearitiesTunnel: This tool replaces sharp activations (e.g., ReLU) with smoother alternatives (e.g., Softplus) during attribution to prevent gradient shattering and stabilize explanations.

3. Datasets and Evaluation

To facilitate benchmarking, tint includes built-in support for both synthetic and real-world datasets. Synthetic datasets like Arma, Hidden Markov Models (HMM), and Hawkes processes are essential because their ground-truth saliency is mathematically defined. Real-world datasets include BioBank and Mimic-III, representing high-stakes clinical environments.

The library distinguishes between "White Box" evaluation (comparing against known ground truth) and "Black Box" evaluation. For the latter, it provides metrics such as comprehensiveness and sufficiency, which quantify the change in model output when "important" features are removed or retained.

4. Key Insights and Results

A central tenet of tint is that context is paramount in time series: a feature's importance is intrinsically linked to when it occurs. The library addresses the "baseline problem" by focusing on distribution-aware baselines, ensuring models are not evaluated on nonsensical, out-of-distribution data.

By leveraging PyTorch Lightning, tint automates the boilerplate code required for handling complex temporal architectures like RNNs and Transformers. The library allows researchers to easily switch between methods like TemporalIntegratedGradients or DynaMask with just a few lines of code, fostering a more rigorous and comparative approach to time series XAI.

5. Conclusion

time_interpret fills a significant gap in the XAI landscape by providing a specialized, unified toolkit for temporal data. While it shares some goals with other libraries like TSInterpret, its unique methods like TIG and LOF-based variants offer powerful tools for researchers. Future work will focus on expanding the suite of temporal-first metrics and supporting a wider range of model architectures.

Summary updated

BibTeX
@misc{enguehard2023time,
  author = {Joseph Enguehard},
  title = {{Time Interpret: a Unified Model Interpretability Library for Time Series}},
  year = {2023},
  eprint = {2306.02968},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.02968},
}
Figure