CLIP-based image captioning via unsupervised cycle-consistency in the latent space

Romain Bielawski, Rufin VanRullenRepL4NLP @ ACL 2023

Introduction

Contrastive Language-Image Pre-training (CLIP) has revolutionized multi-modal learning by aligning images and text into a shared latent space. In theory, this alignment should allow for seamless cross-modal generation: a text decoder trained on CLIP-text features should be able to generate captions from CLIP-image features. However, in practice, a "modality gap" exists. Image and text features occupy slightly different neighborhoods in the latent space, leading to poor performance when visual features are directly fed into a text-trained decoder. This paper proposes a novel Latent CycleGAN architecture to bridge this gap using entirely unsupervised data.

The Modality Gap Challenge

While CLIP aligns modalities for contrastive tasks (like image-text retrieval), the alignment is insufficient for generative tasks. Modality-specific information remains, acting as "noise" that confuses a text decoder. Direct captioning—simply swapping image features for text features—often results in nonsensical or hallucinatory descriptions. Traditionally, researchers solve this with supervised fine-tuning on paired datasets like MS-COCO. The authors of this work investigate whether this alignment can be achieved without any paired image-caption data, relying instead on the geometric structure of the latent space.

Methodology

The proposed pipeline consists of two distinct, unsupervised stages:

Stage 1: Unimodal Text Decoder Training

First, a decoder is trained to reconstruct captions from their own CLIP-text embeddings. This decoder utilizes a mapping network to transform a CLIP embedding into a "prefix" that conditions a frozen GPT-2 model. Crucially, this stage is entirely unimodal, requiring only a corpus of text without any associated images.

Stage 1 involves training a decoder to reconstruct captions from their own CLIP-text embeddings.

Stage 2: Latent CycleGAN for Modality Alignment

To bridge the modality gap, the authors adapt the CycleGAN architecture—traditionally used for pixel-level style transfer—to operate within the 512-dimensional CLIP latent space. This stage uses unpaired data: a set of images and a set of captions with no known ground-truth pairings.

  • Generators: One generator translates image features to text features ($G_{I \to T}$), a process termed "textualisation." A second generator performs the reverse mapping ($G_{T \to I}$).
  • Discriminators: These networks attempt to distinguish between "real" CLIP-text features and "fake" ones translated from images, forcing the generators to produce distribution-aligned features.
  • Cycle-Consistency: The model is penalized if translating an image feature to text and back again does not result in the original vector, ensuring the mapping preserves semantic content.
Unsupervised alignment of text and image features using Latent CycleGAN.

Experimental Results

The "Textualised" approach using the Latent CycleGAN was evaluated on the MS-COCO validation set. Despite being trained without paired data, it vastly outperformed the "Direct" baseline across all standard NLP metrics.

Metric Direct Method (Baseline) Textualised (CycleGAN)
BLEU-1 0.281 0.407
BLEU-4 0.020 0.062
METEOR 0.098 0.161
CIDEr 0.064 0.247

Qualitatively, the textualisation process "cleans" visual features of non-linguistic traits. While the direct method might describe a bathroom as a "CCTV image of restaurant staff," the textualised method produces coherent, relevant descriptions like "A view of a rough and dingy bathroom."

Discussion and Future Work

The success of this method confirms that the geometric structure of image and text distributions in CLIP is similar enough for unsupervised alignment. However, a performance gap still exists between this unsupervised approach and state-of-the-art supervised models. Furthermore, the authors note that using images and captions from the same dataset (COCO) may provide an implicit distributional alignment. Future research will focus on testing this alignment across truly disparate datasets and integrating "textualisation" as a pre-processing layer for large-scale generative models.

Summary updated

BibTeX
@inproceedings{bielawski2023clip,
  author = {Romain Bielawski and Rufin VanRullen},
  title = {{CLIP-based image captioning via unsupervised cycle-consistency in the latent space}},
  booktitle = {RepL4NLP @ ACL},
  year = {2023},
  doi = {10.18653/v1/2023.repl4nlp-1.22},
}
Figure