Exploiting Category Names for Few-Shot Classification with Vision-Language Models

Taihong Xiao, Zirui Wang, Liangliang Cao, Jiahui Yu, Shengyang Dai, Ming-Hsuan Yang

TL;DR

Standard few-shot adaptation of vision-language models typically discards the text encoder and randomly initializes a new classification head, discarding rich semantic priors. This paper introduces Category Name Initialization (CNI): initializing the linear classification head with normalized prompt-averaged text embeddings of the category names. This simple recipe sets state-of-the-art few-shot performance across standard benchmarks—achieving 87.37% on ImageNet with just five shots.

What Problem Does This Paper Address?

Pretrained vision-language models (such as CLIP and CoCa) exhibit impressive zero-shot transfer capabilities because their visual and textual representations share an aligned embedding space. However, when adapting these massive models to downstream tasks with only a few labeled examples per class (e.g., 1-shot or 5-shot learning), practitioners typically append a randomly initialized classification head on top of the vision backbone and fine-tune.

This standard paradigm suffers from two problems:

  1. Severe data-parameter imbalance: Training billions of parameters (or even a high-dimensional head) from scratch on minimal data causes overfitting and decision-boundary distortion.
  2. Ignoring textual priors: It completely ignores the class names, treating downstream categories as arbitrary integer IDs rather than leveraging semantic information already understood by the text encoder.

Methods

The authors evaluate their approach primarily using CoCa (Contrastive Captioners), an encoder-decoder foundation model:

  1. Category Name Initialization (CNI):
  2. For each class category name, the authors generate $N$ prompt variations (e.g., "A photo of many {}").
  3. Text embeddings are generated using the pretrained unimodal text decoder.
  4. For each class, prompt embeddings are averaged and normalized to produce a $D$-dimensional weight vector.
  5. The classification layer $W \in \mathbb{R}^{C \times D}$ is initialized with these normalized vectors, and bias $b$ is initialized to zero, making the starting point equivalent to zero-shot classification.
  6. Selective Fine-Tuning: Rather than tuning the entire network or just the linear layer, the authors demonstrate that updating both the image pooler and the linear projector ($P + L$) yields optimal few-shot performance.
  7. Regularization & Optimization: For extremely scarce data (1-shot), adding $L_2$ weight regularization prevents the limited data from distorting the zero-shot decision boundary.
Category Names + Prompts ──> [Pretrained Text Decoder] ──> Normalized Avg Embedding
                                                                      │
                                                             (Initializes W)
                                                                      ▼
Images ──> [Pretrained Vision Encoder] ──> [Image Pooler (P)] ──> [Linear Head (L)] ──> Softmax

Datasets

The authors evaluated CNI across 13 benchmark datasets:

  • ImageNet-1K and its robustness variants: ImageNet-V2, ImageNet-R, ImageNet-A, and ImageNet-Sketch.
  • Specialized / Fine-Grained benchmarks: Cifar100, Oxford Flowers 102, Stanford Cars, Country-211, Food-101, FGVC Aircraft, EuroSAT, and Oxford-IIIT Pets.
  • No new datasets were introduced.

Key Insights and Ideas

  • Semantic initialization prevents boundary collapse: In 1-shot learning, random initialization provides no meaningful gradient signals, yielding poor transfer (59.17% on ImageNet). CNI starts with calibrated zero-shot decision boundaries, improving 1-shot accuracy to 82.35% (CoCa-base) and 86.15% (CoCa-2B).
  • Semantics matter, even when imperfect:
  • Using arbitrary digits (e.g., "1", "2") provides no semantic boost over random initialization (53.60% vs. 59.17% in 1-shot).
  • Surprisingly, initializing with non-English names (e.g., Spanish or German) still significantly outperforms random initialization (e.g., Spanish reaches 79.87% on 1-shot ImageNet), leveraging subword token sharing in the tokenizer.
  • Partially known categories still help: initializing only 50% of the heads with category names boosts 1-shot accuracy from 59.17% to 66.82%.
  • The $L_2$ Regularization Paradox in Few-Shot Learning: In 1-shot regimes, strong $L_2$ weight regularization protects pretrained zero-shot decision boundaries from catastrophic distortion. In 5-shot regimes, however, the same constraint is actively harmful because it prevents the model from adapting to target domain distributions.

Key Results

  • ImageNet (CoCa-2B):
  • Zero-shot: 86.09%
  • 1-shot (CNI): 86.15%
  • 5-shot (CNI): 87.37% (outperforming prior full-dataset finetuning baselines such as MAE and CLIP ViT-L/14).
  • Fine-Grained Classification (5-shot, CoCa-2B + CNI):
  • Stanford Cars: 96.08% (vs. CLIP 20-shot at 73.60%)
  • Oxford Flowers: 99.25%
  • EuroSAT: 85.78% (a massive leap from 49.74% zero-shot)
  • Oxford-IIIT Pets: 98.12%
  • Knowledge Distillation: Distilling representations from a 1% fine-tuned CoCa-2B into a smaller CoCa-base student boosted CoCa-base accuracy from 83.80% to 84.81%.

Limitations and Future Work

  • Diminishing returns with scale: As downstream training data grows (e.g., 10% to 100% of ImageNet), the performance gap between CNI and random initialization closes entirely.
  • Sensitivity to learning rates: The optimization trajectory is sensitive to initial learning rates; improper tuning causes rapid divergence or performance drops right after early peaks.
  • Label prompt dependency: The initialization depends on text prompt design; while standardized prompts were used, manual prompt design or misaligned class naming may affect domain-specific results.

Summary updated

BibTeX
@inproceedings{xiao2023exploiting,
  author = {Taihong Xiao and Zirui Wang and Liangliang Cao and Jiahui Yu and Shengyang Dai and Ming-Hsuan Yang},
  title = {{Exploiting Category Names for Few-Shot Classification with Vision-Language Models}},
  booktitle = {MRL @ ICLR},
  year = {2023},
  url = {https://openreview.net/forum?id=w25Q9Ttjrs},
}
Figure