Zero-shot image-to-text generation with BLIP-2
BLIP-2 connects a frozen pre-trained image encoder (ViT) to a frozen LLM (OPT or Flan-T5) through a lightweight Querying Transformer (Q-Former), the only trainable component. This cuts trainable parameters and pre-training cost while reaching state-of-the-art results on visual-language tasks. Q-Former is pre-trained in two stages. The first uses image-text contrastive, image-grounded generation and image-text matching losses. The second feeds its query outputs to the LLM as a visual prefix under a causal LM loss. Code examples with Hugging Face Transformers show zero-shot image captioning, prompted captioning, visual question answering with a "Question: Answer:" template, and chat-style prompting, which must stay within the 512-token context.
Related posts
- A Dive into Vision-Language Models
Hugging Face hardMasterVision-language models pair an image encoder and a text encoder with a strategy for fusing the two, and the pre-training objective determines which downstream tasks they handle well. The main families are contrastive learning (CLIP, ALIGN, LiT), PrefixLM and frozen PrefixLM (SimVLM, Frozen, ClipCap, Flamingo), cross-attention fusion into language model layers (VisualGPT, FIBER), combined masked-language modeling and image-text matching (VisualBERT, FLAVA), and training-free methods (MaGiC, ASIF). Frozen-backbone approaches let teams train with limited aligned image-text data, while PrefixLM-only models are mostly limited to captioning and VQA. The post also surveys common pre-training datasets and shows how to experiment with these models in 🤗 Transformers.
- Vision Language Models Explained
Hugging Face mediumAdeptVision language models combine an image encoder, a projector that aligns image features with text embeddings, and a text decoder that generates text from both inputs. LLaVA trains in two stages: first only the projector with the encoder and decoder frozen, then the projector together with an unfrozen decoder. KOSMOS-2 instead trains end to end, and Fuyu-8B skips the image encoder entirely. The guide compares open VLMs by license, size and resolution, explains model selection via Vision Arena, the Open VLM Leaderboard and benchmarks like MMMU and MMBench, then shows inference with transformers' LlavaNext and supervised fine-tuning of Llava 1.5 using TRL's new experimental VLM support in SFTTrainer.
- PaliGemma – Google's Cutting-Edge Open Vision Language Model
Hugging Face mediumAdeptPaliGemma is Google's open vision-language model family that pairs a SigLIP-So400m image encoder with a Gemma-2B text decoder through a linear projector. It ships as pretrained, mix and task-specific fine-tuned checkpoints at 224, 448 and 896 resolutions. Behaviour is steered with task prefixes such as "detect" and "segment", and detections come back as <loc> tokens normalized to 1024. Images become 256 to 4096 prefix tokens with full attention over the image and prompt, so higher resolutions cost much more memory while helping mainly fine-grained tasks like OCR. The post includes transformers code for inference, 4-bit loading, and fine-tuning the decoder with full training or QLoRA, plus big_vision transfer configs.
- SigLIP 2: A better multilingual vision language encoder
Hugging Face mediumAdeptSigLIP 2 is Google's new family of multilingual vision-language encoders that extends SigLIP's sigmoid loss with extra training objectives. These are a text decoder for captioning and region grounding, plus self-distillation with global-local and masked-prediction losses added after 80% of training. Together they improve localization and dense features, and the models outperform SigLIP at every scale on zero-shot classification, retrieval and VLM transfer. New releases include a 1B giant size and NaFlex dynamic-resolution variants that preserve native aspect ratios, along with transformers code for zero-shot classification and image embedding.
- SmolVLM - small yet mighty Vision Language Model
Hugging Face hardMasterSmolVLM is a 2B-parameter open vision language model built on the Idefics3 architecture with a SmolLM2 1.7B backbone. It uses 9x pixel-shuffle compression so each 384x384 patch becomes just 81 tokens. A test prompt plus image encodes to 1.2k tokens versus 16k for Qwen2-VL, giving 5 GB minimum GPU RAM, 3.3-4.5x faster prefill and 7.5-16x faster generation, at modestly lower benchmark scores. Training details cover extending context to 16k by raising the RoPE base to 273k, choosing checkpoints with a weighted benchmark metric, and fine-tuning with QLoRA on a ~16 GB L4 or DPO via TRL.