Mechanistic Interpretability for Transformer-based Time Series Classification

Matīss Kalnāre, Sofoklis Kitharidis, Thomas Bäck, Niki van SteinarXiv 2025

TL;DR

This paper successfully adapts Mechanistic Interpretability (MI) techniques—originally designed for natural language processing—to Time Series Transformers (TSTs). By using activation patching and sparse autoencoders, the authors map internal causal circuits and uncover human-readable temporal motifs that drive classification decisions, proving that time-series models contain discrete, manipulable internal logic.

What Problem Does This Paper Address?

While Transformer-based models have achieved state-of-the-art performance in time series classification (TSC), they remain notorious "black boxes." Traditional Explainable AI (XAI) methods like SHAP or LIME offer surface-level attribution, showing which input timesteps or channels influenced a prediction, but they stop at the model's boundary. They cannot explain how the internal components (layers, attention heads, and neurons) interact to compute the final output.

Mechanistic Interpretability (MI) aims to solve this by reverse-engineering a model's internal circuits. However, doing this for time series introduces unique hurdles: unlike text, time series data lacks discrete tokens, features fluid temporal dependencies, and deals with continuous, variable-length sequences. This paper bridges the gap by adapting NLP-focused MI tools directly to the time-series domain.

Methods

The authors implement a multi-tiered interpretability pipeline using three core techniques:

  1. Activation Patching (Interventional): This method isolates the causal impact of specific internal activations using a "denoising" protocol. The authors select a clean instance (correctly classified with high confidence) and a corrupt instance (misclassified, but from the same true class). They run a forward pass on the corrupt instance but systematically replace ("patch") the activations of specific layers, heads, or timesteps with cached activations from the clean instance to see which components restore the correct prediction.
  2. Attention Saliency (Observational): To complement the causal interventions, they average raw self-attention weights across all query positions to highlight which temporal regions an attention head focuses on.
  3. Sparse Autoencoders (SAEs): To untangle the highly distributed representations inside the model's MLP blocks, the authors train an SAE on the internal activations of the first encoder layer. The SAE uses an $L_1$ regularization penalty to force the network to represent complex internal states using only a few active, semantically meaningful latent features.

By stitching these insights together, the authors construct directed causal graphs tracing the flow of information from input timesteps through internal attention heads to the final class logits.

Datasets

The methodology was evaluated on the JapaneseVowels benchmark, a standard audio time-series dataset containing LPC-derived 12-dimensional frames from nine speakers pronouncing Japanese vowels.

  • Structure: 270 training and 370 test samples.
  • Preprocessing: Sequences were truncated or zero-padded to a uniform length of $T = 25$ frames across 9 target classes.

Key Insights and Ideas

  • Early-Layer Dominance: The causal signal is strongest at the model's entry point. The earliest attention blocks carry the most critical information needed to correct a misclassification, with diminishing returns in deeper layers.
  • Sparse Internal Circuits: The model relies on a surprisingly sparse internal architecture. Out of all available attention heads, only a small handful drive the bulk of the causal computation for a given class.
  • Non-Linear Synergies (Non-Additivity): Summing the causal impacts of individual patched timesteps significantly underestimates the effect of patching an entire attention head. This reveals that the model relies on non-linear synergies across positions—components that are helpful alone can interfere or become redundant when activated together.
  • Latent Feature Specialization: Sparse autoencoders successfully extract human-readable "temporal motifs." For instance, specific SAE neurons learn to fire exclusively in response to class-specific waveform patterns (e.g., simultaneous peaks and dips in specific channels), proving that the model's latent space organizes around robust physical features rather than random noise.

Key Results

The baseline Time Series Transformer achieved an impressive 97.57% accuracy on the JapaneseVowels test set, ensuring the interpretability analysis probed a well-learned structure.

Fig. 1: Confusion matrix of the trained TST on the JapaneseVowels test set. Rows are true classes; columns are predicted classes.

When evaluating layer-wise causal influence, patching all attention heads in Layer 0 yielded the largest increase in true-class probability ($\Delta P \approx 0.89$), confirming that early layers dominate decision-making.

Fig. 2: Change in true-class probability (∆P) when patching all heads of each encoder layer.

Drilling down to individual heads within Layer 0, the authors found that patching just a single head (Head 6) boosted the true-class probability of a misclassified instance from 10.72% to roughly 78.72% ($\Delta P \approx 0.68$).

Head-level activation patching results showing true-class probability change ($\Delta P$) across layers and heads.

Limitations and Future Work

While providing a solid proof-of-concept, the authors note several limitations:

  • Labor-Intensive Pipeline: Selecting representative clean-corrupt pairs and interpreting the resulting motifs still requires significant manual effort and domain expertise.
  • Narrow Component Focus: The current patching experiments focus primarily on attention heads, leaving the causal roles of residual streams, embeddings, and individual neurons largely unexplored.
  • Semantic Ambiguity: Unlike text tokens, time-series features (like audio frequencies) lack inherent semantic labels, making it harder to definitively name the motifs captured by the SAE.

Future directions include expanding activation patching to the entire architecture (MLP blocks and residual streams), automating circuit discovery using optimization algorithms (like evolutionary search), and scaling the framework to higher-dimensional, irregular real-world datasets.

Summary updated

BibTeX
@misc{kalnare2025mechanistic,
  author = {Matīss Kalnāre and Sofoklis Kitharidis and Thomas Bäck and Niki van Stein},
  title = {{Mechanistic Interpretability for Transformer-based Time Series Classification}},
  year = {2025},
  eprint = {2511.21514},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.21514},
}
Figure