{"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/on-the-relationship-between-self-attention-1","title":"On the Relationship between Self-Attention and Convolutional Layers","arxiv_id":"1911.03584","date":"2019-11-08","proceeding":"ICLR 2020 1","authors":["Jean-Baptiste Cordonnier","Andreas Loukas","Martin Jaggi"],"abstract":"Recent trends of incorporating attention mechanisms in vision have led researchers to reconsider the supremacy of convolutional layers as a primary building block. Beyond helping CNNs to handle long-range dependencies, Ramachandran et al. (2019) showed that attention can completely replace convolution and achieve state-of-the-art performance on vision tasks. This raises the question: do learned attention layers operate similarly to convolutional layers? This work provides evidence that attention layers can perform convolution and, indeed, they often learn to do so in practice. Specifically, we prove that a multi-head self-attention layer with sufficient number of heads is at least as expressive as any convolutional layer. Our numerical experiments then show that self-attention layers attend to pixel-grid patterns similarly to CNN layers, corroborating our analysis. Our code is publicly available.","url_abs":"https://arxiv.org/abs/1911.03584v2","url_pdf":"https://arxiv.org/pdf/1911.03584v2.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":"on-the-relationship-between-self-attention-1","repo_url":"https://github.com/epfml/attention-cnn","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"image-classification","task_name":"Image Classification"}],"methods":[{"method_slug":"convolution","method_name":"Convolution"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/image-classification-on-cifar-10","task":"Image Classification","dataset":"CIFAR-10","model":"SA quadratic embedding","rank_in_archive_order":168,"of":265,"metrics":{"Percentage correct":"93.8"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=1911.03584","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"1911.03584"}},"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/epfml/attention-cnn","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran_honours":1,"ran_draft_wrong":3,"unverified":12},"by_repo_kind":{"official":{"samples":16,"ran":4,"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":"fdc64f4c72036ae4","entry":"gelu","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/bert.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/bert.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"fdc64f4c72036ae4"}},{"code_sha256_prefix":"2844a6a8960060bc","entry":"human_format","repo":"epfml/attention-cnn","repo_kind":"official","path":"utils/logging.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/utils/logging.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"2844a6a8960060bc"}},{"code_sha256_prefix":"b6bef72aa7ff57a5","entry":"sizeof_fmt","repo":"epfml/attention-cnn","repo_kind":"official","path":"utils/logging.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/utils/logging.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b6bef72aa7ff57a5"}},{"code_sha256_prefix":"5eff22fa0a651276","entry":"url_to_filename","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/bert_utils.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/bert_utils.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5eff22fa0a651276"}},{"code_sha256_prefix":"1119795bf433256e","entry":"ResNet10","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/resnet.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/resnet.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1119795bf433256e"}},{"code_sha256_prefix":"a4eff019b95fd2ce","entry":"ResNet18","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/resnet.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/resnet.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a4eff019b95fd2ce"}},{"code_sha256_prefix":"af3a6e8a2702592f","entry":"ResNet34","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/resnet.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/resnet.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"af3a6e8a2702592f"}},{"code_sha256_prefix":"cf9c448c96f48428","entry":"cached_path","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/bert_utils.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/bert_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"cf9c448c96f48428"}},{"code_sha256_prefix":"a6aab787fcf8b10d","entry":"filename_to_url","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/bert_utils.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/bert_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a6aab787fcf8b10d"}},{"code_sha256_prefix":"796bf85d9c48fcf1","entry":"gaussian_kernel_2d","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/gaussian.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/gaussian.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"796bf85d9c48fcf1"}},{"code_sha256_prefix":"d5d2fd533e9dac1d","entry":"get_num_parameter","repo":"epfml/attention-cnn","repo_kind":"official","path":"utils/logging.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/utils/logging.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d5d2fd533e9dac1d"}},{"code_sha256_prefix":"14f069410e56d3ba","entry":"linear_warmup_cosine_lr_scheduler","repo":"epfml/attention-cnn","repo_kind":"official","path":"utils/learning_rate.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/utils/learning_rate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"14f069410e56d3ba"}},{"code_sha256_prefix":"b1a7180868dd8d6a","entry":"load_tf_weights_in_bert","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/bert.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/bert.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b1a7180868dd8d6a"}},{"code_sha256_prefix":"c3de407b29c79036","entry":"parse_cli_overides","repo":"epfml/attention-cnn","repo_kind":"official","path":"utils/config.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/utils/config.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c3de407b29c79036"}},{"code_sha256_prefix":"de4b895397bf1813","entry":"plot_attention_layer","repo":"epfml/attention-cnn","repo_kind":"official","path":"utils/plotting.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/utils/plotting.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"de4b895397bf1813"}},{"code_sha256_prefix":"2f516ae7fc833c82","entry":"prune_linear_layer","repo":"epfml/attention-cnn","repo_kind":"official","path":"models/bert.py","file_url":"https://github.com/epfml/attention-cnn/blob/HEAD/models/bert.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"2f516ae7fc833c82"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}