{"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/syntaxshap-syntax-aware-explainability-method","title":"SyntaxShap: Syntax-aware Explainability Method for Text Generation","arxiv_id":"2402.09259","date":"2024-02-14","proceeding":null,"authors":["Kenza Amara","Rita Sevastjanova","Mennatallah El-Assady"],"abstract":"To harness the power of large language models in safety-critical domains, we need to ensure the explainability of their predictions. However, despite the significant attention to model interpretability, there remains an unexplored domain in explaining sequence-to-sequence tasks using methods tailored for textual data. This paper introduces SyntaxShap, a local, model-agnostic explainability method for text generation that takes into consideration the syntax in the text data. The presented work extends Shapley values to account for parsing-based syntactic dependencies. Taking a game theoric approach, SyntaxShap only considers coalitions constraint by the dependency tree. We adopt a model-based evaluation to compare SyntaxShap and its weighted form to state-of-the-art explainability methods adapted to text generation tasks, using diverse metrics including faithfulness, coherency, and semantic alignment of the explanations to the model. We show that our syntax-aware method produces explanations that help build more faithful and coherent explanations for predictions by autoregressive models. Confronted with the misalignment of human and AI model reasoning, this paper also highlights the need for cautious evaluation strategies in explainable AI.","url_abs":"https://arxiv.org/abs/2402.09259v2","url_pdf":"https://arxiv.org/pdf/2402.09259v2.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":"syntaxshap-syntax-aware-explainability-method","repo_url":"https://github.com/k-amara/syntax-shap","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"text-generation","task_name":"Text Generation"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2402.09259","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.09259"}},"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/k-amara/syntax-shap","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":8,"unverified":5},"by_repo_kind":{"official":{"samples":13,"ran":8,"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":"ede50da320fa78ec","entry":"compute_output_dims","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/_explanation.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/_explanation.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":"ede50da320fa78ec"}},{"code_sha256_prefix":"df7238e59087c763","entry":"convert_feat_to_mask","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/explainers/_syntax.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/explainers/_syntax.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":"df7238e59087c763"}},{"code_sha256_prefix":"fabf25aaf5b6c859","entry":"generate_explanatory_masks","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/metrics.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/metrics.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":"fabf25aaf5b6c859"}},{"code_sha256_prefix":"2553ac83ca78410e","entry":"identity","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/links.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/links.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":"2553ac83ca78410e"}},{"code_sha256_prefix":"e3c7e31f2f094463","entry":"is_1d","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/_explanation.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/_explanation.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":"e3c7e31f2f094463"}},{"code_sha256_prefix":"fecc5a713db5e4c9","entry":"logit","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/links.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/links.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":"fecc5a713db5e4c9"}},{"code_sha256_prefix":"5d10648588a144ac","entry":"padleft_mask","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/metrics.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/metrics.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":"5d10648588a144ac"}},{"code_sha256_prefix":"6bd33d5cb64c00c4","entry":"save_path","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/explain.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/explain.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":"6bd33d5cb64c00c4"}},{"code_sha256_prefix":"2a27f190c3200160","entry":"california","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/datasets.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/datasets.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":"2a27f190c3200160"}},{"code_sha256_prefix":"120b0748cd14efa4","entry":"imagenet50","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/datasets.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/datasets.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":"120b0748cd14efa4"}},{"code_sha256_prefix":"473e8cfc361163dc","entry":"load_model","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/model.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/model.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":"473e8cfc361163dc"}},{"code_sha256_prefix":"eda4531c0d51f914","entry":"weight_matrix","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/explainers/_syntax.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/explainers/_syntax.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":"eda4531c0d51f914"}},{"code_sha256_prefix":"725b5bebc44ac43b","entry":"weight_matrix_subset","repo":"k-amara/syntax-shap","repo_kind":"official","path":"syntaxshap/explainers/_syntax.py","file_url":"https://github.com/k-amara/syntax-shap/blob/HEAD/syntaxshap/explainers/_syntax.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":"725b5bebc44ac43b"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}