{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/tokenshap-interpreting-large-language-models","title":"TokenSHAP: Interpreting Large Language Models with Monte Carlo Shapley Value Estimation","arxiv_id":"2407.10114","date":"2024-07-14","proceeding":null,"authors":["Roni Goldshmidt","Miriam Horovicz"],"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.","url_abs":"https://arxiv.org/abs/2407.10114v2","url_pdf":"https://arxiv.org/pdf/2407.10114v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"tokenshap-interpreting-large-language-models","repo_url":"https://github.com/ronigold/TokenSHAP","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"computational-efficiency","task_name":"Computational Efficiency"},{"task_slug":"prompt-engineering","task_name":"Prompt Engineering"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2407.10114","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2407.10114"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ronigold/TokenSHAP","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":9,"unverified":3},"by_repo_kind":{"official":{"samples":12,"ran":9,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"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"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"0f76828d9d9164c6","entry":"create_function_tool","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/tools.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/tools.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0f76828d9d9164c6"}},{"code_sha256_prefix":"679886c1e77b60bf","entry":"create_tool_from_function","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/tools.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/tools.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"679886c1e77b60bf"}},{"code_sha256_prefix":"bc481c4457599f4a","entry":"encode_image_to_base64","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/base.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/base.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"bc481c4457599f4a"}},{"code_sha256_prefix":"41fd7230cab35fe6","entry":"get_text_before_last_underscore","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/base.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/base.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"41fd7230cab35fe6"}},{"code_sha256_prefix":"5ad9e221f5b454a9","entry":"get_text_before_last_underscore","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/token_shap.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/token_shap.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5ad9e221f5b454a9"}},{"code_sha256_prefix":"62fa5ab915e9b213","entry":"load_database","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"experiments/agentshap/exp6_model_comparison.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/experiments/agentshap/exp6_model_comparison.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"62fa5ab915e9b213"}},{"code_sha256_prefix":"0cd7798a11c1b258","entry":"load_module","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"experiments/agentshap/exp6_model_comparison.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/experiments/agentshap/exp6_model_comparison.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0cd7798a11c1b258"}},{"code_sha256_prefix":"7ef2f80a4e2e153d","entry":"load_prompts_from_benchmark","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"experiments/agentshap/exp6_model_comparison.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/experiments/agentshap/exp6_model_comparison.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7ef2f80a4e2e153d"}},{"code_sha256_prefix":"3efd4b0452a3f146","entry":"process_segmentation_results","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/visualization.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/visualization.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3efd4b0452a3f146"}},{"code_sha256_prefix":"cb8d42d00bcf79ba","entry":"create_side_by_side_visualization","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/visualization.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/visualization.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"cb8d42d00bcf79ba"}},{"code_sha256_prefix":"ecdc98a3f24e0937","entry":"interact_with_ollama","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/base.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/base.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ecdc98a3f24e0937"}},{"code_sha256_prefix":"c2612159a9d48d79","entry":"mp4_to_gif_with_styled_title","repo":"ronigold/TokenSHAP","repo_kind":"official","path":"token_shap/visualization.py","file_url":"https://github.com/ronigold/TokenSHAP/blob/HEAD/token_shap/visualization.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c2612159a9d48d79"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}