Explainable Sentence Embeddings

Machine Learning
Introduced by
Conneau et al.; Ribeiro et al. (probing + LIME frameworks)
Year
2016–2018
Type
Post-hoc interpretability applied to sentence encoders
Family
Deep learning / NLP / CV

What does it do?

Explainable sentence embeddings pair dense sentence encoders with interpretability tools, such as probing classifiers, LIME, SHAP, and gradient-based saliency, to test which linguistic and semantic properties can be read from a sentence vector and which input features a downstream prediction is sensitive to.

The aim is to keep the representational power of modern encoders while making their behaviour auditable. The tools differ in their target: probing examines what the encoder represents, while attribution methods examine individual predictions.

The intuition behind the method

A sentence embedding maps an entire sentence to a fixed-length vector in a high-dimensional space, compressing syntax, semantics, and pragmatics into numbers. Without interpretability tools, these numbers are opaque: a classifier trained on them can achieve high accuracy, yet a researcher cannot tell which words, phrases, or linguistic features drove the decision. Explainability methods open the black box in three ways: probing which properties can be decoded from the vectors, perturbing input words to measure how much the output changes, or attributing output scores to individual tokens. Together these make it possible to check, debug, or audit the embedding-based pipeline.

History

Probing classifiers for evaluating sentence representations were systematised by Conneau et al. (2018), who defined ten probing tasks testing syntactic and semantic properties of fixed sentence vectors. LIME (Ribeiro et al., 2016) established model-agnostic, perturbation-based explanation of classifier predictions. SHAP, which applies Shapley values to feature attribution, is commonly used alongside it. As transformer-based sentence encoders such as SBERT became widely used, researchers applied attribution and gradient saliency methods to sentence embeddings.

When to use it

Choose this approach when the downstream use must be justified to others, such as clinical text classification, legal document analysis, or social-science studies that make claims about linguistic content. Probing suits a researcher who wants to know which properties a pre-trained encoder's vectors carry, because it examines the representation itself. LIME and SHAP suit explaining individual predictions to end-users or reviewers. Do not use it when only predictive accuracy matters, since the explanation layer adds analysis effort without changing predictions. Avoid perturbation-based methods when the words substituted or deleted from an input would produce sentences unlike anything the encoder was trained on. Also avoid them when the question is causal, because attribution scores describe the model's sensitivity to its inputs, not causal effects.

Limitations and considerations

  • Probing accuracy conflates what is encoded with what is linearly decodable; high probing accuracy does not guarantee the encoder uses that property for the target task.
  • Perturbation methods can generate semantically incoherent or out-of-distribution sentences, leading to unreliable attribution scores.
  • SHAP is computationally expensive for long documents or large vocabularies.
  • LIME and SHAP outputs depend on the sampling scheme and the background or perturbation set chosen, so attributions must be checked for stability as well as for accuracy.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Tests whether specific linguistic properties, such as syntax, semantics, or sentiment, can be decoded from the sentence vector, enabling theory-driven checks.
  • Post-hoc methods like LIME and SHAP are model-agnostic and can be applied to any encoder without retraining.
  • Probing classifiers provide quantitative evidence about decodability that can be reported and compared across encoders.
  • Attributions show which inputs the output is sensitive to for a given instance, which supports inspection and error analysis; they do not by themselves establish causal claims about the model.
  • Supports error analysis: attributions can highlight candidate failure modes and possible spurious correlations before deployment.
  • Compatible with state-of-the-art encoders (SBERT, BERT-pool, InferSent) without architectural changes.

Applications

  • Clinical NLP: auditing which symptoms or negation cues drive a sentence embedding toward a diagnostic label.
  • Social-science text analysis: verifying that sentiment or stance classifiers respond to theoretically predicted lexical features.
  • Legal document classification: producing token-level attributions for contract clause predictions, which show sensitivity rather than justification.
  • Bias detection: probing whether sentence encoders encode demographic or social stereotypes.
  • Curriculum design: identifying which linguistic complexity features a model has or has not learned.
  • Peer-reviewed NLP research: providing ablation evidence about representational content of new encoder architectures.

How it works

How it works

1

A pre-trained sentence encoder (e.g., SBERT, InferSent, or a pooled BERT output) maps each input sentence to a dense real-valued vector. The encoder is typically frozen or lightly fine-tuned; the resulting embeddings are the objects of interpretation.

2

Either a probing classifier (a lightweight linear model) is trained to predict a specific linguistic property, such as part-of-speech, syntactic depth, or semantic role, from the frozen embedding. Held-out accuracy above a majority-class baseline indicates that the property can be linearly decoded from the vector. Or a perturbation-based method such as LIME generates neighbourhood sentences by substituting or deleting words and measures how much each change shifts the output.

3

Attribution scores are computed for each input token or feature. SHAP estimates Shapley values, which distribute the model output across input features according to the Shapley-value definition from cooperative game theory; for text, this requires a choice of how absent words are represented. Gradient-based saliency computes the gradient of the output with respect to the input embedding. The gradient magnitude is a local sensitivity measure at the given input point: it shows how the output changes for small changes in that embedding, and it does not necessarily equal the importance of a token. Gradients can be misleading for saturated or nonlinear encoders, so large-gradient positions should be checked against perturbation results before being reported as explanations.

4

Attributions and probing results are displayed as heatmaps, attention overlays, or ranked word lists. These displays help researchers check whether the model's sensitivity falls on linguistically meaningful cues, and they flag possible spurious correlations or dataset artefacts for follow-up.

Common pitfalls

  • Treating high probing classifier accuracy as proof that the main model uses the probed property causally.
  • Using LIME with too few perturbation samples, producing unstable and non-reproducible attributions.
  • Reporting only aggregate probing results without checking whether they hold across different sentence lengths, domains, or languages.
  • Ignoring the possibility that attributions reflect the probing or attribution method's own biases rather than the encoder's.
  • Conflating token-level attribution (which word was important) with sentence-level meaning (what the sentence asserts).

Frequently asked questions

What is the difference between probing classifiers and LIME/SHAP for sentence embeddings?

Probing classifiers test whether a property can be decoded from a frozen embedding by training a lightweight model to predict it from the vector; they examine the encoder's representation. LIME and SHAP explain individual predictions by measuring how input changes affect the output; they examine the full pipeline for a specific instance.

Can I apply these methods to any sentence encoder?

Yes. Probing and perturbation-based attribution are encoder-agnostic: they treat the encoder as a black box. Gradient-based saliency requires access to gradients, so it works best with differentiable encoders like BERT-based models.

Does adding interpretability reduce model accuracy?

Post-hoc methods like LIME, SHAP, and probing do not modify the encoder, so they do not change its predictions. Intrinsically interpretable architectures (e.g., sparse or factorized embeddings) may trade some accuracy for transparency.

How many LIME perturbations are sufficient for stable attributions?

There is no fixed safe number. Increase the number of perturbation samples until the attribution scores stop changing noticeably across repeated runs with different random seeds, and report the setting used. Scores that vary between runs should not be reported as explanations.

Is this method suitable for multilingual sentence embeddings?

Yes, but probing tasks must be designed for each language, and cross-lingual alignment should be validated separately. LIME and SHAP can in principle be applied to multilingual encoders, but the perturbations must be plausible in the target language, including its morphology. Check a sample of them with native-speaker review before relying on the attributions.

Related methods

Sources

  1. Conneau, A., Kruszewski, G., Lample, G., Barrault, L., & Baroni, M. (2018). What you can cram into a single $\vec{v}$ector: Probing sentence embeddings for linguistic properties. In Proceedings of ACL 2018, pp. 2126–2136.

    Open publication reference
  2. Ribeiro, M. T., Singh, S., & Guestrin, C. (2016). "Why Should I Trust You?": Explaining the predictions of any classifier. In Proceedings of KDD 2016, pp. 1135–1144.

    Open DOI reference