{"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/lookhere-vision-transformers-with-directed","title":"LookHere: Vision Transformers with Directed Attention Generalize and Extrapolate","arxiv_id":"2405.13985","date":"2024-05-22","proceeding":null,"authors":["Anthony Fuller","Daniel G. Kyrollos","Yousef Yassin","James R. Green"],"abstract":"High-resolution images offer more information about scenes that can improve model accuracy. However, the dominant model architecture in computer vision, the vision transformer (ViT), cannot effectively leverage larger images without finetuning -- ViTs poorly extrapolate to more patches at test time, although transformers offer sequence length flexibility. We attribute this shortcoming to the current patch position encoding methods, which create a distribution shift when extrapolating. We propose a drop-in replacement for the position encoding of plain ViTs that restricts attention heads to fixed fields of view, pointed in different directions, using 2D attention masks. Our novel method, called LookHere, provides translation-equivariance, ensures attention head diversity, and limits the distribution shift that attention heads face when extrapolating. We demonstrate that LookHere improves performance on classification (avg. 1.6%), against adversarial attack (avg. 5.4%), and decreases calibration error (avg. 1.5%) -- on ImageNet without extrapolation. With extrapolation, LookHere outperforms the current SoTA position encoding method, 2D-RoPE, by 21.7% on ImageNet when trained at $224^2$ px and tested at $1024^2$ px. Additionally, we release a high-resolution test set to improve the evaluation of high-resolution image classifiers, called ImageNet-HR.","url_abs":"https://arxiv.org/abs/2405.13985v2","url_pdf":"https://arxiv.org/pdf/2405.13985v2.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":"lookhere-vision-transformers-with-directed","repo_url":"https://github.com/greencubic/lookhere","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"adversarial-attack","task_name":"Adversarial Attack"},{"task_slug":"attribute","task_name":"Attribute"},{"task_slug":null,"task_name":"Avg"},{"task_slug":"diversity","task_name":"Diversity"},{"task_slug":null,"task_name":"Position"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"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":"residual-connection","method_name":"Residual Connection"},{"method_slug":"set","method_name":"SET"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"vision-transformer","method_name":"Vision Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2405.13985","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2405.13985"}},"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/greencubic/lookhere","reach":null}],"summary":{"ran":5,"ran_draft_wrong":1,"ran_honours":2,"unverified":4},"by_repo_kind":{"official":{"samples":12,"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":"b35e50a694a6b62e","entry":"Attention","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b35e50a694a6b62e"}},{"code_sha256_prefix":"01c98d386037421d","entry":"Block","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"01c98d386037421d"}},{"code_sha256_prefix":"3ccd89f9e4648dcc","entry":"BlockwithBiases","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3ccd89f9e4648dcc"}},{"code_sha256_prefix":"90611bff664a489e","entry":"LayerScale","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"90611bff664a489e"}},{"code_sha256_prefix":"9b6612fb34289faa","entry":"VisionTransformer","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9b6612fb34289faa"}},{"code_sha256_prefix":"a5a0ece903d40b24","entry":"create_lh_layer_tensor","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a5a0ece903d40b24"}},{"code_sha256_prefix":"1e0f3ec7d9de62a3","entry":"get_none_slopes","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1e0f3ec7d9de62a3"}},{"code_sha256_prefix":"219b1bd8df9afa74","entry":"get_slopes","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"219b1bd8df9afa74"}},{"code_sha256_prefix":"e0a1b4c82648a897","entry":"AttentionWithBiases","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.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":"e0a1b4c82648a897"}},{"code_sha256_prefix":"90ab0aa30ee2a29d","entry":"LookHere","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.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":"90ab0aa30ee2a29d"}},{"code_sha256_prefix":"7cf9e59d0374ac7f","entry":"create_lh_bias_tensor","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.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":"7cf9e59d0374ac7f"}},{"code_sha256_prefix":"1e6c2f5d71acb2c6","entry":"create_lh_bias_tensor","repo":"greencubic/lookhere","repo_kind":"official","path":"lookhere.py","file_url":"https://github.com/greencubic/lookhere/blob/HEAD/lookhere.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":"1e6c2f5d71acb2c6"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}