Introduction
Generative language models (LMs) like GPT-2 have demonstrated remarkable capabilities in text synthesis. However, grounding these models in non-textual modalities, such as vision, remains a significant hurdle. Traditional approaches often rely on massive datasets of paired image-caption data for supervised training, which is both costly and domain-specific. Alternatively, zero-shot optimization methods like ZeroCap allow LMs to "see" without retraining but suffer from extreme latency due to per-token gradient updates.
This paper introduces MAGIC (iMAge-Guided text generatIon with CLIP), a training-free, "plug-and-play" framework. MAGIC enables off-the-shelf LMs to incorporate visual information during decoding without any gradient updates, achieving state-of-the-art zero-shot results while running nearly 27 times faster than previous optimization-based methods.
Methodology: MAGIC Search
The core of the framework is MAGIC Search, a novel decoding scheme that steers text generation using a multi-part scoring function. Instead of standard greedy or beam search, MAGIC selects the next token $x_t$ by balancing three components:
- Model Confidence: The standard probability of the next token provided by the base LM (e.g., GPT-2).
- Degeneration Penalty: A term that prevents repetitive text, leveraging insights from Contrastive Search.
- The Magic Score: The primary visual control mechanism. It utilizes a pre-trained CLIP model to measure the semantic similarity between the input image and the generated text prefix (including the candidate token).
By computing these scores for the top-$k$ candidate tokens and selecting the highest-scoring one, MAGIC avoids the need for backpropagation during inference. This allows any pre-trained LM to be instantly paired with CLIP for multimodal tasks.
Experimental Setup
The authors evaluated MAGIC across several benchmarks to test its robustness and versatility:
- Zero-Shot Image Captioning: Benchmarked on MS-COCO and Flickr30k, including cross-domain evaluations to prove robustness.
- Visually Grounded Story Generation: Evaluated on the ROCStories dataset.
- Image Retrieval: For storytelling, the model used ConceptualCaptions to retrieve relevant images based on story titles, which then guided the narrative generation.
Results and Discussion
MAGIC achieved a new state-of-the-art in zero-shot image captioning, outperforming ZeroCap on 11 out of 13 metrics across standard datasets. Beyond performance metrics, the efficiency gains are substantial; MAGIC is approximately 27x faster than gradient-based alternatives, making zero-shot multimodal generation viable for real-time applications.
Qualitative analysis highlights MAGIC's superior grounding. While baseline models often hallucinate or miss background details, MAGIC accurately incorporates environmental context.
Human evaluations further support these findings. In story generation tasks, participants rated MAGIC-generated stories as more coherent, fluent, and visually relevant than those produced by text-only baselines like Contrastive Search.
Conclusion
MAGIC demonstrates that visual control can be effectively "plugged" into existing language models through intelligent decoding rather than intensive retraining. By eliminating the need for inference-time optimization, MAGIC provides a scalable and efficient path for multimodal AI. Future work may extend this framework to other modalities like audio or video, provided a suitable cross-modal matching model exists.
Summary updated