An Anchor-based Relative Position Embedding Method for Cross-Modal Tasks

Ya Wang, Xingwu Sun, Fengzong Lian, Zhanhui Kang, Chengzhong Xu

Abstract

Transformers have revolutionized cross-modal tasks, yet they remain fundamentally permutation-invariant, treating text and images as unordered sets without explicit position embeddings. While relative position embeddings (RPE) have succeeded in single-modality contexts, bridging the semantic and coordinate gap between text tokens and image patches remains a challenge. We present ACE-RPE (AnChor-basEd Relative Position Embedding), a novel method that utilizes semantically aligned "anchors" to establish spatial relationships across modalities. ACE-RPE achieves state-of-the-art results on major benchmarks, including Image-Text Retrieval and Visual Reasoning, with minimal computational overhead.

Introduction: The Challenge of Cross-Modal Spatial Awareness

Transformers are the backbone of modern vision-language models, but their inherent lack of spatial awareness necessitates the use of Position Embeddings (PE). In single-modality tasks, Absolute or Relative Position Embeddings effectively encode the order of words or the grid-structure of pixels. However, cross-modal tasks introduce two significant hurdles:

  1. Coordinate Misalignment: Text tokens and image patches do not share a natural coordinate system.
  2. Semantic Gap: The encoding space for linguistic concepts (e.g., the word "horse") is fundamentally different from the raw pixel data of an image patch.

Existing models often process positions independently for each modality, missing the rich spatial-semantic links that define how a specific word relates to a specific region of an image.

The ACE-RPE Framework

To address these challenges, the researchers propose treating the distance between a text token and an image patch as a shortest-path problem through shared "anchors."

The ACE-RPE process: (1) Input pair, (2) Locating anchors, (3) Text-to-text relative positions, and (4) The final anchor-based cross-modal relative positions.

1. Anchor Locating

The model identifies "anchors"—prominent text tokens that can be mapped to specific image patches (e.g., the word "man" linked to the pixels containing a person). This is achieved via an unsupervised Anchor Loss that maximizes similarity between matched pairs without requiring manual bounding-box annotations.

2. Distance Calculation

To determine the relative position between an arbitrary text token ($y_n$) and an image patch ($x_m$), the model calculates a three-step route:

  • Intra-modal Distance: The distance from the text token to a nearby anchor.
  • Semantic Bridge: The jump from the anchor to its corresponding image patch.
  • Inter-modal Distance: The distance from that located patch to the target image patch.

3. Multi-group Relative Position

Similar to multi-head attention, the model employs "multi-group" similarities. This provides a flexible representation of cross-modal distances, allowing the model to capture nuanced spatial relationships across different attention heads.

Architectural Integration

ACE-RPE is integrated directly into the cross-attention layers of the Transformer. Unlike standard models that might only use RPE within separate text or image encoders, ACE-RPE allows the cross-modal encoder to dynamically adjust attention based on the calculated relative positions.

Comparison of architectures: (a) One-stage, (b) Two-stage, and (c) the proposed ACE-RPE which injects relative position information into the cross-modal encoder.

As shown in the architecture comparison, ACE-RPE moves beyond simple Absolute Position Embeddings (APE) or single-modality RPE by introducing a dedicated module that interacts with the cross-modal encoder. This "Contextual Mode" integration is superior to simple bias addition, as it allows the model to weigh positional importance based on the semantic content of the tokens.

Experimental Results and Key Insights

The model was pre-trained on a massive 4.0M image dataset (including MS-COCO, Visual Genome, and Conceptual Captions) and evaluated across six major benchmarks.

  • State-of-the-Art Performance: ACE-RPE outperformed strong baselines like ALBEF on 5 out of 6 benchmarks.
  • Retrieval and Grounding: On Flickr30K, it improved Top-1 Recall for text and image retrieval by over 1%. More significantly, it showed a 2% accuracy jump on RefCOCO+, proving a superior ability to ground text descriptions in specific image regions.
  • Efficiency: The method is highly efficient, adding only 6.1% computational overhead (FLOPs) compared to models without position embeddings.

Conclusion

ACE-RPE transforms the geometric problem of cross-modal alignment into a topological one by using semantic anchors as landmarks. By bridging the gap between text and pixels through these learned landmarks, the model achieves a more profound understanding of spatial-semantic relationships. Future work aims to extend this approach to video-language tasks, where temporal anchors could provide similar benefits for motion and sequence understanding.

Summary updated

BibTeX
@inproceedings{wang2022anchor,
  author = {Ya Wang and Xingwu Sun and Fengzong Lian and Zhanhui Kang and Chengzhong Xu},
  title = {{An Anchor-based Relative Position Embedding Method for Cross-Modal Tasks}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.362},
}
Figure