{"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/fine-grained-visual-textual-alignment-for","title":"Fine-grained Visual Textual Alignment for Cross-Modal Retrieval using Transformer Encoders","arxiv_id":"2008.05231","date":"2020-08-12","proceeding":null,"authors":["Nicola Messina","Giuseppe Amato","Andrea Esuli","Fabrizio Falchi","Claudio Gennaro","Stéphane Marchand-Maillet"],"abstract":"Despite the evolution of deep-learning-based visual-textual processing systems, precise multi-modal matching remains a challenging task. In this work, we tackle the task of cross-modal retrieval through image-sentence matching based on word-region alignments, using supervision only at the global image-sentence level. Specifically, we present a novel approach called Transformer Encoder Reasoning and Alignment Network (TERAN). TERAN enforces a fine-grained match between the underlying components of images and sentences, i.e., image regions and words, respectively, in order to preserve the informative richness of both modalities. TERAN obtains state-of-the-art results on the image retrieval task on both MS-COCO and Flickr30k datasets. Moreover, on MS-COCO, it also outperforms current approaches on the sentence retrieval task. Focusing on scalable cross-modal information retrieval, TERAN is designed to keep the visual and textual data pipelines well separated. Cross-attention links invalidate any chance to separately extract visual and textual features needed for the online search and the offline indexing steps in large-scale retrieval systems. In this respect, TERAN merges the information from the two domains only during the final alignment phase, immediately before the loss computation. We argue that the fine-grained alignments produced by TERAN pave the way towards the research for effective and efficient methods for large-scale cross-modal information retrieval. We compare the effectiveness of our approach against relevant state-of-the-art methods. On the MS-COCO 1K test set, we obtain an improvement of 5.7% and 3.5% respectively on the image and the sentence retrieval tasks on the Recall@1 metric. The code used for the experiments is publicly available on GitHub at https://github.com/mesnico/TERAN.","url_abs":"https://arxiv.org/abs/2008.05231v2","url_pdf":"https://arxiv.org/pdf/2008.05231v2.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":"fine-grained-visual-textual-alignment-for","repo_url":"https://github.com/mesnico/TERAN","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"cross-modal-information-retrieval","task_name":"Cross-Modal Information Retrieval"},{"task_slug":"cross-modal-retrieval","task_name":"Cross-Modal Retrieval"},{"task_slug":"image-retrieval","task_name":"Image Retrieval"},{"task_slug":"information-retrieval","task_name":"Information Retrieval"},{"task_slug":"retrieval","task_name":"Retrieval"},{"task_slug":"sentence","task_name":"Sentence"},{"task_slug":"sentence-retrieval","task_name":"Sentence Retrieval"}],"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/image-retrieval-on-flickr30k-1k-test","task":"Image Retrieval","dataset":"Flickr30K 1K test","model":"TERAN MrSw","rank_in_archive_order":6,"of":18,"metrics":{"R@1":"56.5","R@10":"88.2","R@5":"81.2"},"uses_additional_data":false},{"leaderboard":"/sota/image-retrieval-on-flickr30k-1k-test","task":"Image Retrieval","dataset":"Flickr30K 1K test","model":"TERAN Symm.","rank_in_archive_order":7,"of":18,"metrics":{"R@1":"55.7","R@10":"89.3","R@5":"83.1"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2008.05231","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2008.05231"}},"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/mesnico/TERAN","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran_violates":1,"ran_draft_wrong":1,"unverified":14},"by_repo_kind":{"official":{"samples":16,"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":"894b253f35765276","entry":"generate_square_subsequent_mask","repo":"mesnico/TERAN","repo_kind":"official","path":"models/utils.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/models/utils.py","link_basis":"plan_row","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"894b253f35765276"}},{"code_sha256_prefix":"f92e514b398e75d8","entry":"l2norm","repo":"mesnico/TERAN","repo_kind":"official","path":"models/utils.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/models/utils.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f92e514b398e75d8"}},{"code_sha256_prefix":"e1d7360c5be25e25","entry":"EncoderText","repo":"mesnico/TERAN","repo_kind":"official","path":"models/text.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/models/text.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":"e1d7360c5be25e25"}},{"code_sha256_prefix":"c9ccc8160ca8229a","entry":"average_precision_score","repo":"mesnico/TERAN","repo_kind":"official","path":"evaluate_utils/dcg.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/evaluate_utils/dcg.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":"c9ccc8160ca8229a"}},{"code_sha256_prefix":"7f3908ad08980104","entry":"cosine_sim","repo":"mesnico/TERAN","repo_kind":"official","path":"models/loss.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/models/loss.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":"7f3908ad08980104"}},{"code_sha256_prefix":"f2e17288ada8cf89","entry":"cosine_sim","repo":"mesnico/TERAN","repo_kind":"official","path":"utils.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/utils.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":"f2e17288ada8cf89"}},{"code_sha256_prefix":"f6b4594fd6677dbe","entry":"dcg_score","repo":"mesnico/TERAN","repo_kind":"official","path":"evaluate_utils/dcg.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/evaluate_utils/dcg.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":"f6b4594fd6677dbe"}},{"code_sha256_prefix":"6a49bab714ec6122","entry":"dot_sim","repo":"mesnico/TERAN","repo_kind":"official","path":"models/loss.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/models/loss.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":"6a49bab714ec6122"}},{"code_sha256_prefix":"36545e75ca862270","entry":"dot_sim","repo":"mesnico/TERAN","repo_kind":"official","path":"utils.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/utils.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":"36545e75ca862270"}},{"code_sha256_prefix":"e919b63bdc37e394","entry":"encode_data","repo":"mesnico/TERAN","repo_kind":"official","path":"evaluation.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/evaluation.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":"e919b63bdc37e394"}},{"code_sha256_prefix":"6e963f0bd8b4ec0f","entry":"find_nhead","repo":"mesnico/TERAN","repo_kind":"official","path":"models/visual.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/models/visual.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":"6e963f0bd8b4ec0f"}},{"code_sha256_prefix":"66f891f51e3bec44","entry":"get_paths","repo":"mesnico/TERAN","repo_kind":"official","path":"data.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/data.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":"66f891f51e3bec44"}},{"code_sha256_prefix":"e7518699cbc1bd68","entry":"get_transform","repo":"mesnico/TERAN","repo_kind":"official","path":"data.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/data.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":"e7518699cbc1bd68"}},{"code_sha256_prefix":"d9047caaedf4aadb","entry":"my_collate","repo":"mesnico/TERAN","repo_kind":"official","path":"evaluate_utils/compute_relevance.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/evaluate_utils/compute_relevance.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":"d9047caaedf4aadb"}},{"code_sha256_prefix":"da16023b8239c604","entry":"order_sim","repo":"mesnico/TERAN","repo_kind":"official","path":"models/loss.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/models/loss.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":"da16023b8239c604"}},{"code_sha256_prefix":"8183b31354ef5eef","entry":"ranking_precision_score","repo":"mesnico/TERAN","repo_kind":"official","path":"evaluate_utils/dcg.py","file_url":"https://github.com/mesnico/TERAN/blob/HEAD/evaluate_utils/dcg.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":"8183b31354ef5eef"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}