Transformer Reasoning Network for Image-Text Matching and Retrieval

Nicola Messina, Fabrizio Falchi, Andrea Esuli, Giuseppe AmatoarXiv 2020

TL;DR

The Transformer Encoder Reasoning Network (TERN) is a novel architecture that uses the power of self-attention to separately reason about image regions and text descriptions, mapping them into a shared conceptual space. By moving away from rigid "exact-match" metrics and focusing on semantic relevance, TERN achieves state-of-the-art performance in large-scale image retrieval, proving that Transformers are just as good at visual reasoning as they are at language.

What Problem Does This Paper Address?

In the world of AI, matching an image to a text description (and vice versa) is a cornerstone of search engines and recommendation systems. However, two major hurdles remain:

  1. The Indexing Bottleneck: Many current state-of-the-art models rely on "cross-attention," where the model looks at the image and text simultaneously to find matches. While accurate, this is computationally expensive for large-scale retrieval because you cannot pre-calculate and index features for billions of images and queries separately.
  2. Rigid Evaluation: Most researchers use Recall@K, a metric that only gives points if the model finds the exact ground-truth match. In the real world, if you search for "a dog in a park," a photo of a different dog in a different park is still a "win," but Recall@K would mark it as a failure.

TERN addresses these by creating a "relationship-aware" architecture that processes modalities separately and introduces a more flexible evaluation framework based on semantic similarity.

Methods

The core of the paper is the Transformer Encoder Reasoning Network (TERN). Unlike previous models that might use simple CNNs for images and RNNs for text, TERN uses the Transformer Encoder (TE) architecture for both.

Overview of the TERN architecture, showing how image regions and words are processed through separate but weight-sharing Transformer layers.
  • Visual Reasoning: The model starts with image regions extracted via Faster-RCNN. To give the model "spatial awareness," the authors concatenate these features with normalized bounding-box coordinates (e.g., where the object is and how big it is). These regions are then fed into a stack of Transformer Encoders.
  • Textual Reasoning: The model uses pre-trained BERT embeddings, which already capture context, and passes them through its own pipeline.
  • The "Secret Sauce" - Weight Sharing: To ensure that a "dog" in an image and the word "dog" end up in the same place in the mathematical embedding space, the authors share the weights of the final Transformer layers between the visual and textual pipelines. This forces the model to develop a common abstract concept space.
  • Global Tokens: Borrowing from BERT, the model uses special I-CLS and T-CLS tokens to aggregate global information from the entire set of regions or words into a single, compact vector.
A simplified view of a Transformer Encoder layer, highlighting the self-attention mechanism used for reasoning.

Datasets

The authors evaluated TERN on the MS-COCO dataset, a gold standard in the field containing over 123,000 images, each paired with five human-written captions. They used the standard Karpathy splits for training (113k images), validation (5k), and testing (5k).

Key Insights and Ideas

  • Self-Attention as Reasoning: The authors argue that the self-attention mechanism in Transformers is essentially a reasoning engine. It allows the model to "spot hidden links" between entities—like understanding that a "kid" is the one "kicking" the "ball" based on their spatial and semantic relationships.
  • Beyond Exact Matches: The paper champions the use of NDCG (Normalized Discounted Cumulative Gain). Instead of a binary "right or wrong," they use caption similarity metrics (like SPICE and ROUGE-L) to determine how relevant a non-exact match is. If a retrieved image has a caption very similar to the query, the model gets partial credit.
  • Efficiency for Retrieval: Because TERN produces separate, compact features for images and text, it is highly suitable for real-world applications where images can be pre-indexed in a database, allowing for millisecond-level search.

Key Results

TERN demonstrates that while it might slightly trail some "cross-talking" models on rigid Recall@K metrics, it excels when the goal is finding relevant content.

  • State-of-the-Art on NDCG: On the 1K test set, TERN achieved an NDCG score of 0.653 (using SPICE-based relevance), outperforming the previous best model, VSRN (0.620), by a significant margin.
  • Qualitative Success: The authors show examples where the "ground truth" image isn't necessarily the best match for a query, but TERN successfully finds other highly relevant images that Recall@K would have ignored.
Example of image retrieval results. The red boxes are ground truths, but the other results are clearly relevant to the query.

Limitations and Future Work

  • Loss Function Aggression: The authors note that the hinge-based triplet ranking loss used for training is very "aggressive"—it pushes hard to separate matches from non-matches. They suggest that future work should explore ways to attenuate this behavior to better appreciate "near-misses" during the training phase itself.
  • Reconstruction Constraints: The authors plan to investigate adding reconstruction tasks (e.g., trying to recreate the caption from the visual features) to further refine the shared conceptual space.
  • Hardware Constraints: The study was limited by a batch size of 90 (compared to the standard 128) due to hardware limitations, suggesting there may be even more performance to squeeze out with more compute.

Summary updated

BibTeX
@misc{messina2020transformer,
  author = {Nicola Messina and Fabrizio Falchi and Andrea Esuli and Giuseppe Amato},
  title = {{Transformer Reasoning Network for Image-Text Matching and Retrieval}},
  year = {2020},
  eprint = {2004.09144},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2004.09144},
}
Figure