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

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

14 Jul 2024arXiv:2407.10114archive 2025-07-28

Roni Goldshmidt, Miriam Horovicz

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.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2407.10114")

Code

Syntology Ran 9 of 12 code samples harvested from 1 repository linked to this paper; 3 have no recorded run. Of those that ran: 9 ran with no contract checked.

By repository: official repository: 12 samples from 1 repository, 9 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

ronigold/TokenSHAP officialmentioned on GitHubpytorchMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

12 samples harvested; 9 ran; 0 honoured the contract we drafted; 3 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

9ran
3unverified

Licence: 0 of the 12 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from ronigold/TokenSHAP. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

create_function_tool ronigold/TokenSHAP/token_shap/tools.py official repository ran MIT (permissive) · 0f76828d9d9164c6 · report
create_tool_from_function ronigold/TokenSHAP/token_shap/tools.py official repository ran MIT (permissive) · 679886c1e77b60bf · report
encode_image_to_base64 ronigold/TokenSHAP/token_shap/base.py official repository ran MIT (permissive) · bc481c4457599f4a · report
get_text_before_last_underscore ronigold/TokenSHAP/token_shap/base.py official repository ran fingerprinted MIT (permissive) · 41fd7230cab35fe6 · report
get_text_before_last_underscore ronigold/TokenSHAP/token_shap/token_shap.py official repository ran fingerprinted MIT (permissive) · 5ad9e221f5b454a9 · report
load_database ronigold/TokenSHAP/experiments/agentshap/exp6_model_comparison.py official repository ran MIT (permissive) · 62fa5ab915e9b213 · report
load_module ronigold/TokenSHAP/experiments/agentshap/exp6_model_comparison.py official repository ran MIT (permissive) · 0cd7798a11c1b258 · report
load_prompts_from_benchmark ronigold/TokenSHAP/experiments/agentshap/exp6_model_comparison.py official repository ran MIT (permissive) · 7ef2f80a4e2e153d · report
process_segmentation_results ronigold/TokenSHAP/token_shap/visualization.py official repository ran MIT (permissive) · 3efd4b0452a3f146 · report
create_side_by_side_visualization ronigold/TokenSHAP/token_shap/visualization.py official repository unverified MIT (permissive) · cb8d42d00bcf79ba · report
interact_with_ollama ronigold/TokenSHAP/token_shap/base.py official repository unverified MIT (permissive) · ecdc98a3f24e0937 · report
mp4_to_gif_with_styled_title ronigold/TokenSHAP/token_shap/visualization.py official repository unverified MIT (permissive) · c2612159a9d48d79 · report

Tasks

Computational EfficiencyPrompt Engineering

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections