{"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/batchformer-learning-to-explore-sample","title":"BatchFormer: Learning to Explore Sample Relationships for Robust Representation Learning","arxiv_id":"2203.01522","date":"2022-03-03","proceeding":"CVPR 2022 1","authors":["Zhi Hou","Baosheng Yu","DaCheng Tao"],"abstract":"Despite the success of deep neural networks, there are still many challenges in deep representation learning due to the data scarcity issues such as data imbalance, unseen distribution, and domain shift. To address the above-mentioned issues, a variety of methods have been devised to explore the sample relationships in a vanilla way (i.e., from the perspectives of either the input or the loss function), failing to explore the internal structure of deep neural networks for learning with sample relationships. Inspired by this, we propose to enable deep neural networks themselves with the ability to learn the sample relationships from each mini-batch. Specifically, we introduce a batch transformer module or BatchFormer, which is then applied into the batch dimension of each mini-batch to implicitly explore sample relationships during training. By doing this, the proposed method enables the collaboration of different samples, e.g., the head-class samples can also contribute to the learning of the tail classes for long-tailed recognition. Furthermore, to mitigate the gap between training and testing, we share the classifier between with or without the BatchFormer during training, which can thus be removed during testing. We perform extensive experiments on over ten datasets and the proposed method achieves significant improvements on different data scarcity applications without any bells and whistles, including the tasks of long-tailed recognition, compositional zero-shot learning, domain generalization, and contrastive learning. Code will be made publicly available at https://github.com/zhihou7/BatchFormer.","url_abs":"https://arxiv.org/abs/2203.01522v2","url_pdf":"https://arxiv.org/pdf/2203.01522v2.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":"batchformer-learning-to-explore-sample","repo_url":"https://github.com/zhihou7/batchformer","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"compositional-zero-shot-learning","task_name":"Compositional Zero-Shot Learning"},{"task_slug":"contrastive-learning","task_name":"Contrastive Learning"},{"task_slug":"domain-generalization","task_name":"Domain Generalization"},{"task_slug":"long-tail-learning","task_name":"Long-tail Learning"},{"task_slug":"representation-learning","task_name":"Representation Learning"},{"task_slug":"zero-shot-learning","task_name":"Zero-Shot Learning"},{"task_slug":"zero-shot-learning-domain-generalization","task_name":"Zero-Shot Learning + Domain Generalization"}],"methods":[{"method_slug":"batchformer","method_name":"BatchFormer"}],"datasets_introduced":[],"methods_introduced":[{"slug":"batchformer","name":"BatchFormer","full_name":"Batch Transformer"}],"results":[{"leaderboard":"/sota/domain-generalization-on-pacs-2","task":"Domain Generalization","dataset":"PACS","model":"BatchFormer(ResNet-50, SWAD)","rank_in_archive_order":26,"of":133,"metrics":{"Average Accuracy":"88.6"},"uses_additional_data":false},{"leaderboard":"/sota/long-tail-learning-on-cifar-100-lt-r-100","task":"Long-tail Learning","dataset":"CIFAR-100-LT (ρ=100)","model":"Paco + BatchFormer","rank_in_archive_order":23,"of":66,"metrics":{"Error Rate":"47.6"},"uses_additional_data":false},{"leaderboard":"/sota/long-tail-learning-on-cifar-100-lt-r-100","task":"Long-tail Learning","dataset":"CIFAR-100-LT (ρ=100)","model":"Balanced + BatchFormer","rank_in_archive_order":25,"of":66,"metrics":{"Error Rate":"48.3"},"uses_additional_data":false},{"leaderboard":"/sota/long-tail-learning-on-imagenet-lt","task":"Long-tail Learning","dataset":"ImageNet-LT","model":"BatchFormer(ResNet-50, PaCo)","rank_in_archive_order":28,"of":69,"metrics":{"Top-1 Accuracy":"57.4"},"uses_additional_data":false},{"leaderboard":"/sota/long-tail-learning-on-imagenet-lt","task":"Long-tail Learning","dataset":"ImageNet-LT","model":"BatchFormer(ResNet-50, RIDE)","rank_in_archive_order":35,"of":69,"metrics":{"Top-1 Accuracy":"55.7"},"uses_additional_data":false},{"leaderboard":"/sota/long-tail-learning-on-inaturalist-2018","task":"Long-tail Learning","dataset":"iNaturalist 2018","model":"BatchFormer(ResNet-50, RIDE)","rank_in_archive_order":20,"of":43,"metrics":{"Top-1 Accuracy":"74.1%"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2203.01522","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2203.01522"}},"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/zhihou7/batchformer","reach":{"status":"ok"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/zhihou7/BatchFormer","reach":{"status":"ok"}}],"summary":{"ran":2},"by_repo_kind":{"official":{"samples":2,"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":2,"samples":[{"code_sha256_prefix":"f12ed8081defd51c","entry":"MLPEncoder","repo":"zhihou7/BatchFormer","repo_kind":"official","path":"batchformer-v2/deit_share/bt.py","file_url":"https://github.com/zhihou7/BatchFormer/blob/HEAD/batchformer-v2/deit_share/bt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f12ed8081defd51c"}},{"code_sha256_prefix":"098cbf799656583d","entry":"TransformerDecorator1","repo":"zhihou7/BatchFormer","repo_kind":"official","path":"batchformer-v2/deit_share/bt.py","file_url":"https://github.com/zhihou7/BatchFormer/blob/HEAD/batchformer-v2/deit_share/bt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"098cbf799656583d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}