{"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/xai-for-transformers-better-explanations","title":"XAI for Transformers: Better Explanations through Conservative Propagation","arxiv_id":"2202.07304","date":"2022-02-15","proceeding":null,"authors":["Ameen Ali","Thomas Schnake","Oliver Eberle","Grégoire Montavon","Klaus-Robert Müller","Lior Wolf"],"abstract":"Transformers have become an important workhorse of machine learning, with numerous applications. This necessitates the development of reliable methods for increasing their transparency. Multiple interpretability methods, often based on gradient information, have been proposed. We show that the gradient in a Transformer reflects the function only locally, and thus fails to reliably identify the contribution of input features to the prediction. We identify Attention Heads and LayerNorm as main reasons for such unreliable explanations and propose a more stable way for propagation through these layers. Our proposal, which can be seen as a proper extension of the well-established LRP method to Transformers, is shown both theoretically and empirically to overcome the deficiency of a simple gradient-based approach, and achieves state-of-the-art explanation performance on a broad range of Transformer models and datasets.","url_abs":"https://arxiv.org/abs/2202.07304v2","url_pdf":"https://arxiv.org/pdf/2202.07304v2.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":"xai-for-transformers-better-explanations","repo_url":"https://github.com/ameenali/xai_transformers","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"xai","task_name":"Explainable Artificial Intelligence (XAI)"},{"task_slug":"question-answering","task_name":"Question Answering"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/question-answering-on-newsqa","task":"Question Answering","dataset":"NewsQA","model":"xAI/grok-3-1212","rank_in_archive_order":8,"of":18,"metrics":{"EM":"70.57","F1":"88.24"},"uses_additional_data":true}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2202.07304","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2202.07304"}},"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/ameenali/xai_transformers","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":1,"ran_honours":1,"unverified":10},"by_repo_kind":{"official":{"samples":12,"ran":2,"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":"27481013d8c59da1","entry":"avg_heads","repo":"ameenali/xai_transformers","repo_kind":"official","path":"IMDB/run_imdb.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/IMDB/run_imdb.py","link_basis":"harvester_set","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":"27481013d8c59da1"}},{"code_sha256_prefix":"91fe7a23c1c052b7","entry":"softmax","repo":"ameenali/xai_transformers","repo_kind":"official","path":"attribution.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/attribution.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"91fe7a23c1c052b7"}},{"code_sha256_prefix":"8aae8fd9930a694c","entry":"LayerNorm","repo":"ameenali/xai_transformers","repo_kind":"official","path":"utils.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/utils.py","link_basis":"harvester_set","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":"8aae8fd9930a694c"}},{"code_sha256_prefix":"62d56a2c8e317a8d","entry":"apply_self_attention_rules","repo":"ameenali/xai_transformers","repo_kind":"official","path":"IMDB/run_imdb.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/IMDB/run_imdb.py","link_basis":"harvester_set","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":"62d56a2c8e317a8d"}},{"code_sha256_prefix":"e6f03715bb008a76","entry":"compute_flows","repo":"ameenali/xai_transformers","repo_kind":"official","path":"attribution.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/attribution.py","link_basis":"harvester_set","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":"e6f03715bb008a76"}},{"code_sha256_prefix":"e68f6ccbc2173bdb","entry":"create_data_loader","repo":"ameenali/xai_transformers","repo_kind":"official","path":"IMDB/imdb.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/IMDB/imdb.py","link_basis":"harvester_set","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":"e68f6ccbc2173bdb"}},{"code_sha256_prefix":"38d43b4feccaaa24","entry":"get_adjmat","repo":"ameenali/xai_transformers","repo_kind":"official","path":"attribution.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/attribution.py","link_basis":"harvester_set","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":"38d43b4feccaaa24"}},{"code_sha256_prefix":"7448a1b293e85dc5","entry":"get_sst_dataset","repo":"ameenali/xai_transformers","repo_kind":"official","path":"SST/sst.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/SST/sst.py","link_basis":"harvester_set","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":"7448a1b293e85dc5"}},{"code_sha256_prefix":"3f92118756cbc8b1","entry":"load_imdb","repo":"ameenali/xai_transformers","repo_kind":"official","path":"IMDB/imdb.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/IMDB/imdb.py","link_basis":"harvester_set","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":"3f92118756cbc8b1"}},{"code_sha256_prefix":"c8b195f1d000eaf9","entry":"make_p_layer","repo":"ameenali/xai_transformers","repo_kind":"official","path":"xai_transformer.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/xai_transformer.py","link_basis":"harvester_set","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":"c8b195f1d000eaf9"}},{"code_sha256_prefix":"0918e3d36dec3d64","entry":"rename_params","repo":"ameenali/xai_transformers","repo_kind":"official","path":"IMDB/run_imdb.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/IMDB/run_imdb.py","link_basis":"harvester_set","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":"0918e3d36dec3d64"}},{"code_sha256_prefix":"3ff61564e786e665","entry":"to_sentiment","repo":"ameenali/xai_transformers","repo_kind":"official","path":"IMDB/imdb.py","file_url":"https://github.com/ameenali/xai_transformers/blob/HEAD/IMDB/imdb.py","link_basis":"harvester_set","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":"3ff61564e786e665"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}