SyntaxShap: Syntax-aware Explainability Method for Text Generation

Kenza Amara, Rita Sevastjanova, Mennatallah El-Assady · DOI

Abstract

Large Language Models (LLMs) often lack transparency in their decision-making processes. Traditional explainability methods like SHAP assume feature independence, which fails to capture the syntactic dependencies inherent in natural language. We present SyntaxShap, a model-agnostic framework that incorporates dependency trees into Shapley value calculations. By constraining word coalitions to linguistically valid structures, SyntaxShap produces explanations that are more faithful to model reasoning and computationally efficient.

Introduction: The Challenge of Linguistic Interdependence

As LLMs are increasingly deployed in high-stakes environments, understanding the rationale behind specific token predictions is critical. Standard explainability tools, originally designed for tabular data, often evaluate word importance by removing tokens in random subsets. This process frequently generates "out-of-distribution" nonsense strings that the model was never trained to process, leading to unfaithful explanations. SyntaxShap addresses this by respecting the hierarchical structure of language, ensuring that the "coalitions" of words used to determine importance are grammatically coherent.

Methodology: Syntax-Aware Coalitions

SyntaxShap adapts the game-theoretic Shapley value framework to the rules of linguistics through three key innovations:

  1. Dependency-Constrained Coalitions: Instead of evaluating all possible word combinations, SyntaxShap restricts coalitions to those defined by a sentence's dependency tree. For instance, to assess the importance of a specific word, the algorithm only considers groups formed by following paths within the tree.
  2. Weighted Variant (SyntaxShap-W): This version assigns higher weights to words at the top of the dependency hierarchy (e.g., main verbs and subjects), reflecting the intuition that these tokens provide the syntactic foundation for the rest of the sentence.
  3. Probabilistic Metrics: To account for the generative nature of LLMs, the method employs metrics such as Probability divergence@K and Accuracy@K, which track how well an explanation aligns with the model's top-K predicted tokens.
The SyntaxShap workflow: extracting a dependency tree, forming valid coalitions, and averaging contributions to find word importance.

Experimental Setup

The method was evaluated across three datasets: Generics KB (factual statements), ROCStories (narratives), and a custom Negation dataset designed to test sensitivity to semantic shifts. Comparisons were made against standard baselines, including LIME, SampleShapley, and Partition.

Key Results

SyntaxShap consistently outperformed baseline methods in terms of faithfulness—the degree to which the explanation accurately reflects the model's internal logic. On the Mistral 7B model, SyntaxShap and SyntaxShap-W showed superior performance across all datasets, particularly as the threshold for word importance increased. This is evidenced by higher fidelity and accuracy scores compared to traditional SHAP approximations.

Performance comparison on Mistral 7B: SyntaxShap demonstrates higher fidelity and accuracy compared to standard baselines across multiple datasets.

Furthermore, the method demonstrated high coherency. It successfully distinguished between cases where the model's predictions were similar versus diverse, providing distinct explanations for different model behaviors. This indicates that the syntactic constraints help the method capture the true drivers of the model's output.

Discussion and Insights

A significant finding of this work is the potential for misalignment between "faithful" explanations and human intuition. In experiments with negation, SyntaxShap revealed that models sometimes ignore critical tokens like "not." While a human might find such an explanation "wrong," it is actually a faithful representation of the model's flawed reasoning. This underscores the role of explainability tools as diagnostic instruments rather than just validators of human-like logic.

Additionally, by pruning the search space to syntactically valid combinations, SyntaxShap offers significant efficiency gains. The computational complexity is reduced from exponential to a more manageable polynomial form based on the tree structure, making it more scalable for longer sentences.

Limitations and Future Directions

Currently, SyntaxShap is limited to single-sentence analysis due to its reliance on individual dependency trees. Future research will explore extending the method to multi-sentence contexts and incorporating more granular linguistic roles (e.g., distinguishing between function and content words) to further refine importance weighting.

Summary updated

BibTeX
@inproceedings{amara2024syntaxshap,
  author = {Kenza Amara and Rita Sevastjanova and Mennatallah El-Assady},
  title = {{SyntaxShap: Syntax-aware Explainability Method for Text Generation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.270},
}
Figure