Abstract
Inspired by retrieval-augmented language generation and pretrained Vision and Language (V&L) encoders, we present a new approach to image captioning that generates sentences given the input image and a set of captions retrieved from a datastore, as opposed to the image alone. The encoder in our model jointly processes the image and retrieved captions using a pretrained V&L BERT, while the decoder attends to the multimodal encoder representations, benefiting from the extra textual evidence from the retrieved captions. Experimental results on the COCO dataset show that image captioning can be effectively formulated from this new perspective. Our model, named EXTRA, benefits from using captions retrieved from the training dataset, and it can also benefit from using an external dataset without the need for retraining. Ablation studies show that retrieving a sufficient number of captions (e.g., k=5) can improve captioning quality. Our work contributes towards using pretrained V&L encoders for generative tasks, instead of standard classification tasks.
Introduction
Standard image captioning models typically follow a strict "vision-to-language" pipeline: an encoder processes an image, and a decoder attempts to generate a description from scratch. While effective, this approach relies entirely on the visual features present in a single input image. This is akin to asking a person to describe a complex, unfamiliar scene without any prior context or reference.
In contrast, humans often rely on analogies or memories of similar scenes when describing the world. Furthermore, while pretrained Vision-and-Language (V&L) BERT models (such as LXMERT or UNITER) have achieved state-of-the-art performance on discriminative tasks like Visual Question Answering, their potential for generative tasks remains under-explored. We introduce EXTRA (Encoder with X-modal representations Through Retrieval Augmentation), a model that provides the generator with a "cheat sheet" of existing captions from similar images to guide the generation process.
The EXTRA Architecture
The EXTRA framework consists of three primary components designed to integrate visual and retrieved textual information:
- The Retrieval System: Given a query image, the system utilizes CLIP (Contrastive Language-Image Pre-training) to embed the image into a shared feature space. It then employs FAISS (Facebook AI Similarity Search) to efficiently retrieve the $k$ most similar captions from a large datastore, typically the training set.
- The Multimodal Encoder: Rather than a standard visual-only encoder, EXTRA uses LXMERT, a pretrained V&L BERT. This encoder jointly processes the input image—represented as 36 object regions extracted via Faster-RCNN—and the $k$ retrieved captions. This architecture allows the model to capture complex cross-modal interactions between the new pixels and existing human language.
- The Generative Decoder: A GPT-2 based transformer serves as the decoder. We modify the standard GPT-2 architecture by adding cross-attention layers, enabling the model to "look back" at the multimodal representations produced by the LXMERT encoder while generating the final caption token-by-token.
Experimental Setup and Training
We evaluated EXTRA primarily on the MS COCO dataset using the standard Karpathy splits (113k training images). To test the model's flexibility across domains, we also utilized the Flickr30K dataset.
The training process involves two stages:
- Cross-Entropy Loss: Initial training to establish basic language modeling and alignment.
- Self-Critical Sequence Training (SCST): Fine-tuning to directly optimize for the CIDEr metric, which rewards the model for generating captions that are more similar to human references.
Key Insights and Results
Performance and Robustness
EXTRA achieved results competitive with state-of-the-art specialized captioning models. On the COCO test split, the model reached a CIDEr score of 131.1 after SCST optimization. Ablation studies confirmed that the model is not merely using the retrieved text as a generic prompt; providing random or empty captions significantly degraded performance, proving that the model extracts specific, relevant semantic information from the retrieved set.
The Role of Retrieval Volume
Our experiments indicate that increasing the number of retrieved captions ($k$) enhances model robustness. While a single retrieved caption might be a "mismatch" (e.g., misidentifying a dog as a cat), a set of five captions allows the model to aggregate information and effectively ignore outliers, leading to more accurate descriptions.
Attention Dynamics
By analyzing the decoder's attention weights, we observed a distinct shift in focus. In the early layers of the decoder, the model attends to both the image regions and the retrieved text. However, in deeper layers, the model relies almost exclusively on the retrieved textual information. This suggests that the image sets the initial semantic stage, while the retrieved captions provide the linguistic template for the final output.
"Hot-Swapping" Knowledge
A significant advantage of the EXTRA architecture is its adaptability. In a "hot-swapping" experiment, a model trained on Flickr30K was allowed to retrieve captions from the much larger COCO datastore during inference. This resulted in a performance boost without any additional training, demonstrating a form of zero-shot knowledge expansion that is impossible for standard "closed" models.
Conclusion and Future Work
EXTRA demonstrates that image captioning can be significantly improved by treating it as a retrieval-augmented task. By leveraging pretrained V&L encoders for generation, we bridge the gap between discriminative and generative multimodal AI.
Future research will address current limitations, such as the potential for the model to inherit social biases present in the datastore. Additionally, we aim to explore multilingual retrieval sets and end-to-end training, where the retrieval mechanism and the generator are optimized jointly to identify the most helpful textual context for the decoder.
Summary updated