- Introduced by
- Lundberg & Lee (SHAP); Ribeiro et al. (LIME); community synthesis
- Year
- 2017–2019
- Type
- Interpretable deep learning (post-hoc explainability)
- Family
- Deep learning / NLP / CV
What does it do?
Explainable LSTM pairs a trained Long Short-Term Memory network with post-hoc explanation methods, such as SHAP, LIME, integrated gradients, or attention visualization, to show which time steps, tokens, or features contribute to each prediction.
The LSTM itself is not modified; the explanation is computed afterwards from the trained model. It is used where sequential models must justify individual outputs, for example in clinical decision support, fraud detection, and regulatory compliance.
The intuition behind the method
An LSTM processes a sequence one step at a time and carries information forward in memory cells, so its internal state is hard to read directly. Post-hoc methods probe the trained model from outside, by varying or perturbing inputs and observing how the output changes. SHAP assigns each input a contribution value based on Shapley values from cooperative game theory. LIME fits a simple interpretable model around a single prediction. Integrated gradients accumulates gradients along a path from a baseline input to the actual input. These methods give approximate, input-level answers to questions such as which words or sensor readings pushed a prediction, but they describe the model's behaviour rather than the causal process that generated the data.
History
Explainability methods for complex models became a central concern in the mid-2010s, as recurrent networks such as LSTMs were deployed in clinical and financial settings. Ribeiro, Singh and Guestrin (2016) introduced LIME, a method for explaining the individual predictions of any classifier. Lundberg and Lee (2017) proposed SHAP as a unified framework for interpreting model predictions. Explainable LSTM therefore applies these general-purpose explanation methods to LSTM models rather than being a single method introduced alongside the LSTM itself.
When to use it
Choose Explainable LSTM when sequential data (text, time series, or sensor streams) calls for an LSTM or a variant such as BiLSTM or stacked LSTM, and the trained model already meets the required predictive accuracy. It fits cases where individual predictions must be justified to stakeholders or auditors, such as clinical NLP, financial risk, or anomaly detection. Do not use it when a simpler interpretable model, such as logistic or linear regression, already performs adequately, since that model is transparent by construction. Post-hoc explanations cannot recover structure the LSTM did not learn, and they become unreliable when the LSTM underfits or overfits.
Limitations and considerations
- SHAP estimation on long sequences is costly in time and memory, and a background sample is usually needed to keep it tractable.
- A high attention weight does not show that a time step or token changed the output, so attention is not a reliable substitute for attribution.
- Attributions approximate the trained model's behaviour and do not establish causal effects in the underlying data.
- Explanations inherit the quality of the LSTM; a model that generalises poorly yields misleading attributions.
- On long sequences the attribution space has one value per time step and feature, which is difficult to display compactly.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Keeps the predictive capacity of the LSTM, because the explanation is computed from the trained network without altering it.
- SHAP attributions are built on Shapley-value axioms (including local accuracy and consistency), which gives a principled basis for comparing feature contributions.
- Provides local attributions for single predictions and global rankings obtained by averaging over many predictions.
- Applies to standard LSTM variants, including BiLSTM, stacked LSTM, and attention-augmented LSTM.
- Can expose spurious correlations or data leakage when attributions point to inputs that should not matter, which supports debugging.
- Produces per-prediction records that can support audit trails in regulated settings such as healthcare and finance.
Applications
- Clinical NLP: identifying which symptoms or clinical notes drive risk predictions in patient trajectories.
- Financial time-series: attributing fraud alerts or credit decisions to specific transaction windows.
- Predictive maintenance: highlighting sensor time steps that indicate imminent equipment failure.
- Legal and regulatory text classification: providing audit trails for automated document categorization.
- Sentiment analysis: pinpointing which phrases most influence sentiment polarity scores.
- Scientific literature analysis: explaining topic or claim classification for systematic review tools.
How it works
How it works
A standard LSTM is trained on the sequential task (classification, regression, or forecasting) using a conventional procedure. Explanation is applied afterwards to the trained model, so the architecture and training are unchanged. Explanations are only as reliable as this model, so its predictive fit should be checked first.
The explainer is chosen according to data type and the question being asked. SHAP-based explainers, such as DeepExplainer or GradientExplainer, are used for feature attribution in deep models; for deep networks they typically rely on approximations rather than exact Shapley enumeration. LIME builds a locally faithful surrogate around one prediction; integrated gradients attributes the output along a path from a baseline to the input. Attention weights can be inspected only when the LSTM contains an attention mechanism, and they should not be treated as attributions on their own.
The explainer assigns each feature or time step a score. The formula above is the general Shapley value, where F is the set of features and f(S) is the model output when only the features in S are present. SHAP uses these values and, by its local accuracy property, the attributions sum to the difference between the model output for the given input and the expected output over the background data: the sum of phi_i equals f(x) minus E[f(X)]. Scores can be computed for each prediction or averaged over many predictions to give a global importance ranking.
Formula
\phi_i = \sum_{S \subseteq F \setminus \{i\}} \frac{|S|!(|F|-|S|-1)!}{|F|!}[f(S\cup\{i\})-f(S)]Attribution scores are displayed as heatmaps over time steps, bar charts of feature importance, or force plots showing how each factor moves the prediction above or below the baseline. For text, token-level highlighting is typical; for time series, importance plotted across time windows shows which periods drive the output.
Explanations are checked with faithfulness tests. Choose the masking unit first (a token for text, a time step or time window for time series, or a feature channel), then measure how performance changes when the top-attributed units are kept (sufficiency) or masked (necessity). Compare against the same number of randomly chosen units, repeated several times, and report the metric used. As a sanity check, recompute attributions after randomizing the model weights; if they barely change, they are not reflecting what the model learned. Domain experts can then judge whether the highlighted features agree with known domain knowledge; this is a separate check from faithfulness and does not replace it.
Common pitfalls
- Treating attention weights as ground-truth explanations without checking them against SHAP or gradient-based attributions.
- Reporting only global feature importance without checking whether individual predictions show a different pattern.
- Skipping faithfulness tests; always check that masking the top-attributed features degrades performance more than masking random features.
- Explaining predictions from an LSTM that has not been checked for calibration or overfitting.
- Presenting SHAP plots to non-specialists without stating the baseline and the sign convention.
- Choosing a baseline for integrated gradients without reporting it, since the baseline changes the attribution values.
Frequently asked questions
Can I use SHAP with any LSTM architecture?
Not necessarily. SHAP provides explainers for deep models, but support depends on the library and framework, so check that the explainer accepts your LSTM layers. For long sequences, a background sample is needed to keep the computation tractable.
Are attention weights the same as explainability?
No. Attention weights describe an internal weighting in the model and do not necessarily reflect how much each input changed the output. Attention should be supplemented with a rigorous attribution method and a faithfulness test before it is presented as an explanation.
What is a good baseline for integrated gradients in text tasks?
The baseline should represent an uninformative input for your model. Common options are an all-zero embedding or a mean embedding, but a zero vector is not neutral for every model. For time series, the mean of the training sequences or a zero-valued series is often used. The baseline affects attribution magnitudes, so report it explicitly and test how sensitive the results are to alternative choices.
How do I validate that my explanations are faithful?
Use sufficiency and necessity tests: measure performance when only the top-attributed features are kept (sufficiency) and when they are masked (necessity), using a defined unit such as a token or time step. If the explanation is faithful, removing the top features should reduce performance more than removing the same number of random features. Also run a randomized-weights sanity check.
When should I use LIME instead of SHAP for an LSTM?
LIME is useful for a quick local explanation of a single prediction and works with any model that can be queried, including a black-box API. SHAP is generally preferred for systematic analyses that require consistent attributions across many predictions, because it is grounded in Shapley-value axioms.
Related methods
Sources
Lundberg, S. M., & Lee, S.-I. (2017). A unified approach to interpreting model predictions. Advances in Neural Information Processing Systems, 30, 4765–4774.
Open publication referenceRibeiro, M. T., Singh, S., & Guestrin, C. (2016). "Why should I trust you?": Explaining the predictions of any classifier. Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 1135–1144.
Open DOI reference