How do Decisions Emerge across Layers in Neural Models? Interpretation with Differentiable Masking

Nicola De Cao, Michael Sejr Schlichtkrull, Wilker Aziz, Ivan Titov

Abstract

Attribution methods assess the contribution of inputs to the model prediction. One way to do so is erasure: a subset of inputs is considered irrelevant if it can be removed without affecting the prediction. Though conceptually simple, erasure's objective is intractable and approximate search remains expensive with modern deep NLP models. Erasure is also susceptible to the hindsight bias: the fact that an input can be dropped does not mean that the model 'knows' it can be dropped. To deal with these challenges, we introduce Differentiable Masking (DiffMask). DiffMask learns to mask-out subsets of the input while maintaining differentiability. The decision to include or disregard an input token is made with a simple model based on intermediate hidden layers of the analyzed model. This makes the approach efficient and reveals what the network 'knows' at the corresponding layers, allowing for an analysis of how decisions are formed across network layers.

Introduction

Deep learning models, particularly Large Language Models (LLMs) like BERT, are notoriously "black boxes." While we can observe the final prediction, understanding why a model chose a specific answer is difficult. Existing "attribution methods," which assign importance to input words, often suffer from hindsight bias. For example, in a question-answering task, a simple erasure method might identify only the final answer as "important" because the model can still guess correctly if everything else is deleted. However, this doesn't reflect the model's actual internal logic—it needs context to know what to look for in the first place.

The authors of this study aim to create a method that is faithful to the model's internal state, showing not just what could be removed, but what the model knows it can ignore at each stage of its processing.

Methodology: Differentiable Masking (DIFFMASK)

The researchers introduce DIFFMASK, a new interpretability method that uses differentiable masking to reveal how neural networks make decisions layer-by-layer. Instead of searching for the smallest subset of words to keep—a computationally expensive task—they train a simple "interpreter" model (a probe) alongside the original frozen model.

The DIFFMASK architecture: an interpreter $g_\phi^{(\ell)}$ predicts masks based on hidden states $h^{(\ell)}$ to produce a gated input $\hat{x}$, which is then passed through the remaining layers to compare outputs.

Key technical components include:

  • Layer-wise Probing: The interpreter looks at the hidden states of the model at a specific layer $\ell$ and predicts a binary mask (keep/discard) for each input token.
  • Differentiable Gates: To make the binary "keep or discard" decision searchable via gradient descent, they use the Hard Concrete distribution. This allows the model to learn sparse, nearly-binary masks while remaining end-to-end differentiable.
  • Amortization: Unlike methods that require a fresh optimization for every single sentence, DIFFMASK learns a general strategy across the training set, making it much faster at test time.
  • Baseline Vectors: Since "deleting" a word in a vector space is complex, they replace discarded tokens with a learned "baseline" vector that represents an uninformative input.

Experimental Setup

The researchers evaluated DIFFMASK on three distinct tasks to test its versatility and accuracy:

  1. A Toy Task: A synthetic dataset where the model must count if there are more "8s" than "1s" in a sequence. This provides a "ground truth" for attribution.
  2. Sentiment Classification: Using the Stanford Sentiment Treebank (SST) to analyze BERT-base.
  3. Question Answering: Using the SQuAD v1.1 dataset to analyze BERT-large.

Key Insights and Results

The "Aha!" Moment

In Question Answering, the model doesn't immediately know what is irrelevant. For a 24-layer BERT model, it takes about 13–16 layers of processing before the model "realizes" that a distractor sentence (like one mentioning a different hotel) can be safely ignored. This suggests a transition from general linguistic processing to task-specific reasoning in the middle layers.

Superiority over Erasure

On the toy task, DIFFMASK achieved a Jensen-Shannon divergence of 0.00 from the ground truth attribution, significantly outperforming standard erasure (0.27) and other popular methods like Integrated Gradients (0.27).

Comparison of attribution methods on a toy task. Standard methods like Erasure search (a) and Integrated Gradients (c) often produce noisy or biased results, whereas DIFFMASK aims for a perfect match with the ground truth logic.

Input vs. Hidden State Importance

The tokens the model needs as input (like adjectives in sentiment analysis) are often different from the hidden states it needs to keep. For instance, special tokens like [SEP] and [CLS] are often discarded as inputs early on but are kept as hidden states until the very last layer because they act as "mailboxes" where information from the whole sentence is aggregated.

Efficiency and Stability

Because DIFFMASK is amortized, it reaches optimal solutions for masking much more frequently (32.67% of the time) compared to REINFORCE-based methods (8.83%) while being significantly faster. Furthermore, the attributions provided by DIFFMASK were found to be highly stable across different training runs, with a standard deviation of only 0.03–0.05.

Conclusion and Future Work

DIFFMASK demonstrates that faithfulness to a model's internal state is crucial for accurate interpretation. By avoiding hindsight bias, it provides a clearer picture of the linguistic hierarchy within BERT, where simple features are discarded early and complex entities are maintained deeper into the network.

While powerful, the method relies on a "baseline" vector to represent masked tokens, and training probes for every layer of a massive model requires significant initial computation. Future work could involve using DIFFMASK to "prune" models—permanently removing the parts of the network that the probes identify as consistently irrelevant.

Summary updated

Abstract

Attribution methods assess the contribution of inputs to the model prediction. One way to do so is erasure: a subset of inputs is considered irrelevant if it can be removed without affecting the prediction. Though conceptually simple, erasure's objective is intractable and approximate search remains expensive with modern deep NLP models. Erasure is also susceptible to the hindsight bias: the fact that an input can be dropped does not mean that the model `knows' it can be dropped. The resulting pruning is over-aggressive and does not reflect how the model arrives at the prediction. To deal with these challenges, we introduce Differentiable Masking. DiffMask learns to mask-out subsets of the input while maintaining differentiability. The decision to include or disregard an input token is made with a simple model based on intermediate hidden layers of the analyzed model. First, this makes the approach efficient because we predict rather than search. Second, as with probing classifiers, this reveals what the network `knows' at the corresponding layers. This lets us not only plot attribution heatmaps but also analyze how decisions are formed across network layers. We use DiffMask to study BERT models on sentiment classification and question answering.
BibTeX
@inproceedings{cao2020how,
  author = {Nicola De Cao and Michael Sejr Schlichtkrull and Wilker Aziz and Ivan Titov},
  title = {{How do Decisions Emerge across Layers in Neural Models? Interpretation with Differentiable Masking}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  url = {https://openreview.net/forum?id=TwXcYUxvyFn},
}
Figure