{"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/quantifying-attention-flow-in-transformers","title":"Quantifying Attention Flow in Transformers","arxiv_id":"2005.00928","date":"2020-05-02","proceeding":"ACL 2020 6","authors":["Samira Abnar","Willem Zuidema"],"abstract":"In the Transformer model, \"self-attention\" combines information from attended embeddings into the representation of the focal embedding in the next layer. Thus, across layers of the Transformer, information originating from different tokens gets increasingly mixed. This makes attention weights unreliable as explanations probes. In this paper, we consider the problem of quantifying this flow of information through self-attention. We propose two methods for approximating the attention to input tokens given attention weights, attention rollout and attention flow, as post hoc methods when we use attention weights as the relative relevance of the input tokens. We show that these methods give complementary views on the flow of information, and compared to raw attention, both yield higher correlations with importance scores of input tokens obtained using an ablation method and input gradients.","url_abs":"https://arxiv.org/abs/2005.00928v2","url_pdf":"https://arxiv.org/pdf/2005.00928v2.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":"quantifying-attention-flow-in-transformers","repo_url":"https://github.com/samiraabnar/attention_flow","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"tf","reach":null},{"paper_slug":"quantifying-attention-flow-in-transformers","repo_url":"https://github.com/jacobgil/vit-explain","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"quantifying-attention-flow-in-transformers","repo_url":"https://github.com/leemsaebom/attention-guided-cam-visual-explanations-of-vision-transformer-guided-by-self-attention","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"quantifying-attention-flow-in-transformers","repo_url":"https://github.com/mt-upc/transformer-contributions","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"quantifying-attention-flow-in-transformers","repo_url":"https://github.com/vasgaowei/TS-CAM","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"quantifying-attention-flow-in-transformers","repo_url":"https://github.com/vasgaowei/ts-cam-voc","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"quantifying-attention-flow-in-transformers","repo_url":"https://github.com/yiyixuxu/TimeSformer-rolled-attention","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[],"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":"relu","method_name":"ReLU"},{"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":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2005.00928","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2005.00928"}},"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/yiyixuxu/TimeSformer-rolled-attention","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/mt-upc/transformer-contributions","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/vasgaowei/TS-CAM","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/vasgaowei/ts-cam-voc","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/jacobgil/vit-explain","reach":null},{"provenance":"deterministic:regex_extraction","url":"https://github.com/samiraabnar/attention_flow","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/leemsaebom/attention-guided-cam-visual-explanations-of-vision-transformer-guided-by-self-attention","reach":null}],"summary":{"ran_fixture":2,"unverified":6},"by_repo_kind":{"official":{"samples":1,"ran":0,"repositories":1},"listed":{"samples":6,"ran":2,"repositories":4}},"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":6,"samples":[{"code_sha256_prefix":"b71e31585fecd495","entry":"compute_joint_attention","repo":"mt-upc/transformer-contributions","repo_kind":"listed","path":"src/utils_contributions.py","file_url":"https://github.com/mt-upc/transformer-contributions/blob/HEAD/src/utils_contributions.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b71e31585fecd495"}},{"code_sha256_prefix":"5b7e4e55c4239a5f","entry":"create_video_input","repo":"yiyixuxu/TimeSformer-rolled-attention","repo_kind":"listed","path":"visualize_attn_util.py","file_url":"https://github.com/yiyixuxu/TimeSformer-rolled-attention/blob/HEAD/visualize_attn_util.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"DEP_MISSING","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5b7e4e55c4239a5f"}},{"code_sha256_prefix":"412f47c929382c33","entry":"DividedAttentionRollout","repo":"yiyixuxu/TimeSformer-rolled-attention","repo_kind":"listed","path":"visualize_attn_util.py","file_url":"https://github.com/yiyixuxu/TimeSformer-rolled-attention/blob/HEAD/visualize_attn_util.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"412f47c929382c33"}},{"code_sha256_prefix":"eaadbe978c71548a","entry":"combine_divided_attention","repo":"yiyixuxu/TimeSformer-rolled-attention","repo_kind":"listed","path":"visualize_attn_util.py","file_url":"https://github.com/yiyixuxu/TimeSformer-rolled-attention/blob/HEAD/visualize_attn_util.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"eaadbe978c71548a"}},{"code_sha256_prefix":"6f25137dea73163a","entry":"compute_flows","repo":"samiraabnar/attention_flow","repo_kind":"official","path":"attention_graph_util.py","file_url":"https://github.com/samiraabnar/attention_flow/blob/HEAD/attention_graph_util.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6f25137dea73163a"}},{"code_sha256_prefix":"7c6f43d2449917c6","entry":"get_frames","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"7c6f43d2449917c6"}},{"code_sha256_prefix":"84871575d6e5f5d9","entry":"rollout","repo":"jacobgil/vit-explain","repo_kind":"listed","path":"vit_rollout.py","file_url":"https://github.com/jacobgil/vit-explain/blob/HEAD/vit_rollout.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":"84871575d6e5f5d9"}},{"code_sha256_prefix":"f06c5e0a3af9b83c","entry":"rollout","repo":"leemsaebom/attention-guided-cam-visual-explanations-of-vision-transformer-guided-by-self-attention","repo_kind":"listed","path":"Methods/AttentionRollout/AttentionRollout.py","file_url":"https://github.com/leemsaebom/attention-guided-cam-visual-explanations-of-vision-transformer-guided-by-self-attention/blob/HEAD/Methods/AttentionRollout/AttentionRollout.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f06c5e0a3af9b83c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}