Table of Contents
Fetching ...

TokenSHAP: Interpreting Large Language Models with Monte Carlo Shapley Value Estimation

Roni Goldshmidt, Miriam Horovicz

TL;DR

TokenSHAP addresses the challenge of interpreting large language models by attributing importance to individual tokens or substrings via Shapley values. A Monte Carlo estimator computes token contributions using a value function $v(S)=\text{cosine\_similarity}(\text{TF-IDF}(r(S)), \text{TF-IDF}(r(N)))$, where $r(S)$ is the model response to subset $S$ and $r(N)$ to the full input. Empirical results show TokenSHAP outperforms baselines in discriminating irrelevant tokens and reveals nuanced token interactions, with analysis of sampling strategies underscoring robustness and efficiency. The approach is scalable, model-agnostic, and supports applications in prompt engineering, bias analysis, and responsible AI deployment in critical domains.

Abstract

As large language models (LLMs) become increasingly prevalent in critical applications, the need for interpretable AI has grown. We introduce TokenSHAP, a novel method for interpreting LLMs by attributing importance to individual tokens or substrings within input prompts. This approach adapts Shapley values from cooperative game theory to natural language processing, offering a rigorous framework for understanding how different parts of an input contribute to a model's response. TokenSHAP leverages Monte Carlo sampling for computational efficiency, providing interpretable, quantitative measures of token importance. We demonstrate its efficacy across diverse prompts and LLM architectures, showing consistent improvements over existing baselines in alignment with human judgments, faithfulness to model behavior, and consistency. Our method's ability to capture nuanced interactions between tokens provides valuable insights into LLM behavior, enhancing model transparency, improving prompt engineering, and aiding in the development of more reliable AI systems. TokenSHAP represents a significant step towards the necessary interpretability for responsible AI deployment, contributing to the broader goal of creating more transparent, accountable, and trustworthy AI systems.

TokenSHAP: Interpreting Large Language Models with Monte Carlo Shapley Value Estimation

TL;DR

TokenSHAP addresses the challenge of interpreting large language models by attributing importance to individual tokens or substrings via Shapley values. A Monte Carlo estimator computes token contributions using a value function , where is the model response to subset and to the full input. Empirical results show TokenSHAP outperforms baselines in discriminating irrelevant tokens and reveals nuanced token interactions, with analysis of sampling strategies underscoring robustness and efficiency. The approach is scalable, model-agnostic, and supports applications in prompt engineering, bias analysis, and responsible AI deployment in critical domains.

Abstract

As large language models (LLMs) become increasingly prevalent in critical applications, the need for interpretable AI has grown. We introduce TokenSHAP, a novel method for interpreting LLMs by attributing importance to individual tokens or substrings within input prompts. This approach adapts Shapley values from cooperative game theory to natural language processing, offering a rigorous framework for understanding how different parts of an input contribute to a model's response. TokenSHAP leverages Monte Carlo sampling for computational efficiency, providing interpretable, quantitative measures of token importance. We demonstrate its efficacy across diverse prompts and LLM architectures, showing consistent improvements over existing baselines in alignment with human judgments, faithfulness to model behavior, and consistency. Our method's ability to capture nuanced interactions between tokens provides valuable insights into LLM behavior, enhancing model transparency, improving prompt engineering, and aiding in the development of more reliable AI systems. TokenSHAP represents a significant step towards the necessary interpretability for responsible AI deployment, contributing to the broader goal of creating more transparent, accountable, and trustworthy AI systems.
Paper Structure (31 sections, 2 equations, 6 figures, 1 table, 1 algorithm)

This paper contains 31 sections, 2 equations, 6 figures, 1 table, 1 algorithm.

Figures (6)

  • Figure 1: Flowchart of the TokenSHAP algorithm illustrating the process of Shapley value estimation for token importance in large language models by accepting parts of the text to the players and a cosine similarity measure to the base prompt as a gain.
  • Figure 2: A graph that shows the visualization of the prompt in blue-red colors.
  • Figure 3: Box plot showing the distribution of importance values for the Random Baseline method.
  • Figure 4: Box plot showing the distribution of importance values for the Prompt Engineering method.
  • Figure 5: Box plot showing the distribution of importance values for TokenSHAP.
  • ...and 1 more figures